Backup and Restore Gitea server

Anything can happen in these difficult times

Page content

Need to backup the 1) db, 2) filestorage, 3) some other gitea files. Here we go.

very nice photo of opened hdd

In the Testing Gitea post we installed the gitea server.

When

Now just as a precaution of terrible things happenings, need to rehearse the backup and restore procedure.

Better be safe then sorry.

Where

Gitea server data consists of 3 components

  • code
  • filestore
  • db

In our test environment all togeather they take a bit more then 700MB:

gitea disk usage

As they recommend, need to stop all services and back up them all, kind of in the same transaction.

And restore, in the same transaction too.

How - Backup

cd ~/gitea-srv-local

# backup the db
sudo docker exec -t gitea-srv-local_db_1 bash -c 'pg_dump gitea -U gitea  --file=/var/lib/postgresql/backups/gitea-db-$(date +%Y-%m-%d).sql'

# take gitea down
sudo docker-compose down

# check the backups folder
sudo ls postgres-backups

# create backup dir
mkdir gitea-backups

# backup gitea folder
sudo tar -zcvf gitea-backups/gitea-gitea-$(date +%Y-%m-%d).tgz gitea/gitea

# backup repos folder
sudo tar -zcvf gitea-backups/gitea-git-$(date +%Y-%m-%d).tgz gitea/git

# bring it up
sudo docker-compose up -d

last bit - login to some other server and pull backup folder there, or do some other more elaborated files manipulation

scp -r uname@gitea-srv-ip-addr:/home/uname/gitea-srv-local/gitea-backups ~/gitea-backups
scp -r uname@gitea-srv-ip-addr:/home/uname/gitea-srv-local/postgres-backups ~/postgres-backups

How - Restore

Actually, there is a bit more then that, esp with permissions and hooks, but idea is the same.

But! check the original doco: https://docs.gitea.com/administration/backup-and-restore

# install it first
# then take it down
sudo docker-compose down

# restore files
tar -zxvf gitea-git-___.tgz gitea/git
tar -zxvf gitea-gitea-___.tgz gitea/gitea

# bring it up
sudo docker-compose up -d

# here some activity with psql or pg_restore
sudo docker exec -t gitea-srv-local_db_1 bash -c 'psql gitea -U gitea  --file=/var/lib/postgresql/backups/gitea-db-$(date +%Y-%m-%d).sql'

Then goto UI and check it