Skip to content

Backup and restore Gitea

Backup:

  1. Switch to user git and switch to home directory
sudo su git
cd
  1. Run the Gitea dump command
gitea dump -c /etc/gitea/app.ini

This will produce a gitea dump .zip file.

Restore from scratch:

Prerequisites

  1. Install Git
sudo apt install git
  1. Install MariaDB
sudo apt install mariadb-server mariadb-client
  1. Configure MariaDB
sudo mysql_secure_installation

A few questions will be asked, including setting a root password. This is the password for MariaDB, and is not the root password of the PC.

Enter current password for root (enter for none): Just press the Enter
Set root password? [Y/n]: Y
New password: Enter password
Re-enter new password: Repeat password
Remove anonymous users? [Y/n]: Y
Disallow root login remotely? [Y/n]: Y
Remove test database and access to it? [Y/n]:  Y
Reload privilege tables now? [Y/n]:  Y
  1. Restart MariaDB
sudo systemctl restart mariadb.service
  1. Log into MariaDB
sudo mysql -u root -p
  1. Create database called gitea
CREATE DATABASE giteadb;
  1. Create a database user called giteauser. Give it a password which Gitea will use to log into the database.
CREATE USER 'giteauser'@'localhost' IDENTIFIED BY 'new_password_here';
  1. Now save your changes and exit
FLUSH PRIVILEGES;
EXIT;
  1. Download Gitea
sudo wget -O gitea https://dl.gitea.io/gitea/1.5.0/gitea-1.5.0-linux-amd64
sudo chmod +x gitea
  1. Copy the binary to a global location
sudo cp gitea /usr/local/bin/gitea

Restore with dump

  1. Go to the folder where the gitea dump .zip file is located and unzip it
unzip gitea-dump-123456789.zip
cd gitea-dump-1482906742
  1. Move .ini file to correct location
mv custom/conf/app.ini /etc/gitea/app.ini
# or mv app.ini /etc/gitea/app.ini
  1. Unzip the repos and move it to the correct location
unzip gitea-repo.zip
mv gitea-repo/* /var/lib/gitea/repositories/
  1. Change ownership
chown -R gitea:gitea /etc/gitea/conf/app.ini /var/lib/gitea/repositories/
  1. Now import the database into the newly made one. Replace $DATABASE with the database name, in this case giteadb.
mysql --default-character-set=utf8mb4 -u root -p $DATABASE < gitea-db.sql
# or  sqlite3 $DATABASE_PATH <gitea-db.sql

Final touches

  1. Log into MariaDB
sudo mysql -u root -p
  1. Now grant the user full access to the database
GRANT ALL ON gitea.* TO 'giteauser'@'localhost' IDENTIFIED BY 'user_password_here' WITH GRANT OPTION;
  1. Now save your changes and exit
FLUSH PRIVILEGES;
EXIT;
  1. Restart gitea to apply changes and check the status
service gitea restart
service gitea status

Now you should be able to acces gitea via ip-address:3000.


Source: https://docs.gitea.io/en-us/backup-and-restore/