Backup Gitlab
|
Check Volumes
To back up Gitlab, it is not sufficient to back up the data and configurations. Gitlab offers a possibility to perform a backup via Docker. |
Preparations
Create volumes for the configuration files, log and data and for the backups. These should be stored in the docker-compose.yml:
volumes:
- './data:/var/opt/gitlab'
- ./config:/etc/gitlab
- ./logs:/var/log/gitlab
- ./backups:/var/opt/gitlab/backups
Backup
Open an instance of the running Gitlab Docker container and create the backup using the dedicated Gitlab Rake script:
~$ docker exec gitlab gitlab-rake gitlab:backup:create
...
done
done
done
Deleting old backups ... skipping
Warning: Your gitlab.rb and gitlab-secrets.json files contain sensitive data
and are not included in this backup. You will need these files to restore a backup.
Please back them up manually.
Backup task is done.
This backup file is saved in the folder /var/opt/git/backups The mentioned files (gitlab.rb and gitlab-secrets.json) are stored inside the ./config folder.
Restore
Start an empty working instance with the existing docker-compose.yml file, but without the volume folders. Then copy the backup file into the /var/opt/gitlab/backups folder.
~$ docker cp 13692447_2023_04_05_14.5.6_gitlab_backup.tar gitlab:/var/opt/gitlab/backups
Stop unicorn:
~$ docker exec gitlab gitlab-ctl stop puma
ok: down: puma: 0s, normally up
and sidekiq process:
~$ docker exec gitlab gitlab-ctl stop sidekiq
ok: down: sidekiq: 0s, normally up
Change permissions of the backups folder:
~$ docker exec gitlab chmod -R 755 /var/opt/gitlab/backups
Restoring the backup is done with :
~$ docker exec -it gitlab /bin/bash
root@f86d62c99203:/# gitlab-rake gitlab:backup:restore
Unpacking backup ... done
Be sure to stop Puma, Sidekiq, and any other process that
connects to the database before proceeding. For Omnibus
installs, see the following link for more information:
https://docs.gitlab.com/ee/raketasks/backup_restore.html#restore-for-omnibus-gitlab-installations
Before restoring the database, we will remove all existing
tables to avoid future upgrade problems. Be aware that if you have
custom tables in the GitLab database these tables and all data will be
removed.
Do you want to continue (yes/no)? yes
Removing all tables. Press `Ctrl-C` within 5 seconds to abort
2023-10-15 20:21:51 +0000 -- Cleaning the database ...
2023-10-15 20:21:53 +0000 -- done
2023-10-15 20:21:53 +0000 -- Restoring database ...
Restoring PostgreSQL database gitlabhq_production ... ERROR: must be owner of extension pg_trgm
ERROR: must be owner of extension btree_gist
ERROR: must be owner of extension btree_gist
...
...
2023-10-15 20:22:06 +0000 -- Restoring packages ...
2023-10-15 20:22:06 +0000 -- done
This task will now rebuild the authorized_keys file.
You will lose any data stored in the authorized_keys file.
Do you want to continue (yes/no)? yes
Deleting backups/tmp ... done
Warning: Your gitlab.rb and gitlab-secrets.json files contain sensitive data
and are not included in this backup. You will need to restore these files manually.
Restore task is done.
Confirm with 'yes' 2 time.
Restart the services (this can take serveral minutes):
~$ docker exec gitlab gitlab-ctl start
Check that all file permissions and software versions are correct.
docker exec gitlab gitlab-rake gitlab:check SANITIZE=true
Checking GitLab subtasks ...
Checking GitLab Shell ...
GitLab Shell: ... GitLab Shell version >= 13.22.2 ? ... OK (13.22.2)
Running /opt/gitlab/embedded/service/gitlab-shell/bin/check
Internal API available: OK
Redis available via internal API: OK
gitlab-shell self-check successful
Checking GitLab Shell ... Finished
Checking Gitaly ...
Gitaly: ... default ... OK
Checking Gitaly ... Finished
Checking Sidekiq ...
Sidekiq: ... Running? ... yes
Number of Sidekiq processes (cluster/worker) ... 1/1
Checking Sidekiq ... Finished
Checking Incoming Email ...
Incoming Email: ... Reply by email is disabled in config/gitlab.yml
Checking Incoming Email ... Finished
Checking LDAP ...
LDAP: ... LDAP is disabled in config/gitlab.yml
Checking LDAP ... Finished
Checking GitLab App ...
Git configured correctly? ... yes
Database config exists? ... yes
All migrations up? ... yes
Database contains orphaned GroupMembers? ... no
GitLab config exists? ... yes
GitLab config up to date? ... yes
Log directory writable? ... yes
Tmp directory writable? ... yes
Uploads directory exists? ... yes
Uploads directory has correct permissions? ... yes
Uploads directory tmp has correct permissions? ... skipped (no tmp uploads folder yet)
Systemd unit files or init script exist? ... skipped (omnibus-gitlab has neither init script nor systemd units)
Systemd unit files or init script up-to-date? ... skipped (omnibus-gitlab has neither init script nor systemd units)
Projects have namespace: ...
2/1 ... yes
1/2 ... yes
1/3 ... yes
1/4 ... yes
1/5 ... yes
1/6 ... yes
1/7 ... yes
Redis version >= 5.0.0? ... yes
Ruby version >= 2.7.2 ? ... yes (2.7.5)
Git version >= 2.33.0 ? ... yes (2.33.1)
Git user has default SSH configuration? ... yes
Active users: ... 1
Is authorized keys file accessible? ... yes
GitLab configured to store new projects in hashed storage? ... yes
All projects are in hashed storage? ... yes
Checking GitLab App ... Finished
Checking GitLab subtasks ... Finished