Gitea setup, backup and restore

Several posts about Gitea GIT server and how to devops it

Recently I’ve published several docs on how to setup and use Gitea GIT server - have a look if you are interested in this.

Running your own git server shouldn’t be too difficult, right?

So now choosing free git server from a very short list of options. Bonobo Gogs vs Gitea vs Gitlab.

  • Bonobo though is free but for windows, and doesn’t have a linux version.
  • Gitlab is feature-rich and resource-heavy, that’s a hands on experience. It’s a commertial product but has a free version too.
  • The Gogs is very light-weight, I’ve tried it and it worked well, but it’s missing a container registry

The comparison favors Gitea in my eyes…

See more on: Choosing free on-prem git server - Gitea is the winner: https://www.glukhov.org/post/2024/04/gitea/

In addition to serving as a git server, Gitea can host docker registry.

And - here are short list of steps to make when we need the registry in k8s -

  • Step 1 - Install Apache and create simple test site
  • Step 2 - Converting this site to insecure reverse proxy :) to Gitea
  • Step 3 Self - signed root CA and site cert
  • Step 4 - Securing proxy with self-signed certificate
  • Now k8s test
  • Do some DNSing…
  • Root CA
  • Create secret with registry credentials
  • New docker image and k8s deployment

More details in the post: Gitea SSL with Apache as reverse proxy

You can check the detailed description on https://www.glukhov.org/post/2024/05/gitea-backup-restore/ but putting it short, see below:

Gitea storage consists of 3 parts:

  • DB
  • gitea storage
  • git repositories storage

My backup Gitea server script:

bash

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

Restore gitea server script

bash

# 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-___.sql'