Backup and restore data for Gitlab CE

by Daniel Pham
Published: Updated:
This entry is part 4 of 9 in the series Install Gitlab CE on Ubuntu 18

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.

Backup and restore data for Gitlab CE
Backup and restore data for Gitlab CE.

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.

  1. 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
  2. Configuration files and ssl cert files. In short, the /etc/gitlab directory.
    • /etc/gitlab/gitlab-secrets.json
    • /etc/gitlab/gitlab.rb
  3. Firewall rule file

To backup, create a temporary folder to contain the 3 data you need to backup above.

mkdir -p /tmp/backup

File and database data

Gitlab provides a command that allows us to quickly create backup data.

gitlab-backup create

After 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/backup

2. Configuration files

Copy the entire /etc/gitlab directory to the temporary backup directory.

cp -rp /etc/gitlab /tmp/backup

3. 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/backup

4. 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/backup

You 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/backup

Restore 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.tar

Next, you stop Gitlab services that are connecting to the database.

gitlab-ctl stop unicorn
gitlab-ctl stop puma
gitlab-ctl stop sidekiq
gitlab-ctl status

Then 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.1

Restore configuration files

Change the current /etc/gitlab directory to the old version.

mv /etc/gitlab /etc/gitlab_old

Then 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=true

Conclusion

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.

0 0 votes
Article Rating
Series Navigation«« Previous part: Set up SMTP mail for Gitlab CENext part: Script to backup Gitlab CE data to Amazon S3 »»

You may also like

Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments

DevOps Lite is a personal blog specializing in technology with main topics about DevOps, DevSecOps, SRE and System Administrator. Articles are shared for free and contributed to the community.

SUPPORT US

FOLLOW US

Subscribe my Newsletter for new blog posts. Stay updated from your inbox!

© 2021-2024 DevOpsLite.com – All rights reserved.

Please write sources “DevOpsLite.com” when using articles from this website.

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More

0
Would love your thoughts, please comment.x
()
x

Adblock Detected

Please support us by disabling your AdBlocker extension from your browsers for our website.