Table of Contents
Backup and restore data for Gitlab CE. Next in the series, we will learn the steps to backup data for Gitlab CE and restore data when problems occur.

Gitlab itself has also provided a fairly complete documentation on Backup & Restore data for the Gitlab CE server.
However, this article makes it easier for you to understand and can do immediately.
Backup data for Gitlab CE
Gitlab CE runs so many different service packages that it will take you a long time to learn them all.
If you plan to backup each service individually within Gitlab, that is not necessary.
In general, a Gitlab server will have 3 pieces of data that you need to backup.
- File and database data include:
- Database
- Attachments
- Git repositories data
- CI/CD job output logs
- CI/CD job artifacts
- LFS objects
- Container Registry images
- GitLab Pages content
- Configuration files and ssl cert files. In short, the
/etc/gitlabdirectory.- /etc/gitlab/gitlab-secrets.json
- /etc/gitlab/gitlab.rb
- Firewall rule file
To backup, create a temporary folder to contain the 3 data you need to backup above.
mkdir -p /tmp/backupFile and database data
Gitlab provides a command that allows us to quickly create backup data.
gitlab-backup createAfter the command finishes running, it will create a .tar backup file located in the /var/opt/gitlab/backups directory.
The file has the format xxxxxxxxxx_yyyy_mm_dd_12.8.1_gitlab_backup.tar.
You move that backup file into the temporary backup folder. Remember to replace xxxxxxxxxx_yyyy_mm_dd_12.8.1 with the exact name of the file.
mv /var/opt/gitlab/backups/xxxxxxxxxx_yyyy_mm_dd_12.8.1_gitlab_backup.tar /tmp/backup2. Configuration files
Copy the entire /etc/gitlab directory to the temporary backup directory.
cp -rp /etc/gitlab /tmp/backup3. Firewall rule file
Depending on the type of firewall on the server you are using. For example, with Ubuntu 18.04 and I am using IPtables.
cp -rp /etc/iptables/rules.v4 /tmp/backup4. Pack everything up and transfer it to the backup server
Now use the command below to package the temporary backup folder with all the backup data inside.
tar -cvzf backup.tar.gz /tmp/backupYou can then copy this backup.tar.gz file to the backup server via rsync or to cloud storage services such as Google Drive, One Drive, Amazon S3…
Finally, delete the temporary backup data.
rm -f backup.tar.gz
rm -rf /tmp/backupRestore data to Gitlab CE
Restoring data will do the opposite of the backup process. As for the firewall rule, I do not need to mention it during the data recovery process. You just need to reload the rule file and you’re done.
Note: you need to run the same version of Gitlab as the backup version before performing restore operations
Restore database backup files
First, copy the database backup file into the backup directory of the Gitlab server.
cp xxxxxxxxxx_yyyy_mm_dd_12.8.1_gitlab_backup.tar /var/opt/gitlab/backups/Then, you assign the owner of the backup file to the git user.
chown git.git /var/opt/gitlab/backups/xxxxxxxxxx_yyyy_mm_dd_12.8.1_gitlab_backup.tarNext, you stop Gitlab services that are connecting to the database.
gitlab-ctl stop unicorn
gitlab-ctl stop puma
gitlab-ctl stop sidekiq
gitlab-ctl statusThen you run the command to restore the backup file with the file’s time stamp and version.
gitlab-backup restore xxxxxxxxxx_yyyy_mm_dd_12.8.1Restore configuration files
Change the current /etc/gitlab directory to the old version.
mv /etc/gitlab /etc/gitlab_oldThen copy the gitlab folder in the backup file to the /etc/ directory on the current server.
cp gitlab /etc/Note: Check the configuration files in the /etc/gitlab folder you just copied.
Reconfigure the system
Finally, reapply the backup configuration to the system.
gitlab-ctl reconfigure
gitlab-ctl restart
gitlab-rake gitlab:check SANITIZE=trueConclusion
With this article, you can completely understand the steps to backup and restore data for the Gitlab CE system. Hopefully this article will help you have one more step of peace of mind for your system.