Migrating Forgejo and Gitea
This section describes migrating Forgejo/Gitea data between two Momod servers.
Forgejo (Gitea) has backup and restore documentation. We can move our Forgejo data between Momod servers using that method.
- Stop Forgejo
sudo systemctl stop gitea
- Switch to user running Forgejo
sudo su -s /bin/bash gitea
- Run gitea dump
cd /tmp
/usr/local/bin/forgejo dump -c /etc/gitea/gitea.ini
exit
This should generate a file in /tmp with a name like ‘forgejo-dump-1694445847.zip’. Chown the file to yourself and move it to your home directory ready for download. From your home directory on the server and substituting USER with your own user account name:
sudo mv /tmp/forgejo-dump-1694445847.zip .
sudo chown USER:USER forgejo-dump-1694445847.zip
It is recommended not to trust the database dump in this file and instead generate one with database native tools.
To generate database dump with mariadb tools:
mariadb-dump -u forgejo -p --database forgejo > forgejo-db.sql
Enter the forgejo_db_password variable you have set on the old server.
Copy these two files, the forgejo-dump and forgejo-db, to the new server.
Restoring Forgejo
This very much a manual process of copying data to the correct location and restoring the database dump.
Before starting copy the forgejo-dump and forgejo-db to the new server, then stop Forgejo on that server too.
sudo systemctl stop gitea
Unzip the dump and move the contents to the right locations:
mkdir forgejo-old
unzip -d forgejo-old forgejo-dump-1694445847.zip
cd forgejo-old
sudo mv app.ini /etc/gitea/gitea.ini
sudo rm -rf /var/lib/gitea/data/home /var/lib/gitea/data/jwt /var/lib/gitea/data/queues /var/lib/gitea/data/ssh /var/lib/gitea/data/tmp
sudo mv -f data/* /var/lib/gitea/data/
sudo mv log/* /var/lib/gitea/log/
sudo mv repos/* /var/lib/gitea/repos/
sudo chown -R gitea:gitea /etc/gitea/gitea.ini /var/lib/gitea
Restore the database dump and restart Forgejo
z
mariadb --default-character-set=utf8mb4 -u forgejo -p forgejo < forgejo-db.sql
sudo systemctl start gitea
This will also have copied the gitea.ini file containing the old servers FQDN, if your FQDN has changed you need to rerun the Forgejo role. Either by editing play/dev.yml and running that play or by running the update play:
ansible-playbook --limit NEWSERVER play/update.yml
You should now be able to log into Forgejo - you can check the base url is now set to the correct FQDN in Site Administration section of Forgejo.