Backup and restore Gitea
Backup:
- Switch to user git and switch to home directory
sudo su git
cd
- Run the Gitea dump command
gitea dump -c /etc/gitea/app.ini
This will produce a gitea dump .zip file.
Restore from scratch:
Prerequisites
- Install Git
sudo apt install git
- Install MariaDB
sudo apt install mariadb-server mariadb-client
- 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
- Restart MariaDB
sudo systemctl restart mariadb.service
- Log into MariaDB
sudo mysql -u root -p
- Create database called gitea
CREATE DATABASE giteadb;
- 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';
- Now save your changes and exit
FLUSH PRIVILEGES;
EXIT;
- Download Gitea
sudo wget -O gitea https://dl.gitea.io/gitea/1.5.0/gitea-1.5.0-linux-amd64
sudo chmod +x gitea
- Copy the binary to a global location
sudo cp gitea /usr/local/bin/gitea
Restore with dump
- Go to the folder where the gitea dump .zip file is located and unzip it
unzip gitea-dump-123456789.zip
cd gitea-dump-1482906742
- Move .ini file to correct location
mv custom/conf/app.ini /etc/gitea/app.ini
# or mv app.ini /etc/gitea/app.ini
- Unzip the repos and move it to the correct location
unzip gitea-repo.zip
mv gitea-repo/* /var/lib/gitea/repositories/
- Change ownership
chown -R gitea:gitea /etc/gitea/conf/app.ini /var/lib/gitea/repositories/
- 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
- Log into MariaDB
sudo mysql -u root -p
- Now grant the user full access to the database
GRANT ALL ON gitea.* TO 'giteauser'@'localhost' IDENTIFIED BY 'user_password_here' WITH GRANT OPTION;
- Now save your changes and exit
FLUSH PRIVILEGES;
EXIT;
- 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/