Site icon Aditya Mittal Inc.

How to Backup and Restore Omnibus GitLab

How to Backup and Restore Omnibus GitLab

When we backup GitLab, there are two components that need to be backed up:

  1. GitLab Configuration Files
  2. Gitlab Application Files

1. GitLab Configuration Backup

GitLab configuration files consist of user information who are using two-factor authentication. If you do not back-up the configuration files, the users will lose access to the GitLab server.

The GitLab configuration file is located in: /etc/gitlab/gitlab-secrets.json

The command to backup GitLab configuration file is as follows:

# sudo gitlab-ctl backup-etc <DIRECTORY>

By default, the configuration backup is stored in : /etc/gitlab/config_backup/.

Daily Backup

You can create a daily backup as a root user by using the following command:

# sudo crontab -e -u root

Daily back-up will run every day at 04:30 AM:

30 04 * * * sudo gitlab-ctl backup-etc

Restore from Backup

To restore the backup file, you need to extract the tar file by using this command:

# sudo tar -xf gitlab_config_1487687824_date.tar -C /

Next, run sudo gitlab-ctl reconfigure after restoring a configuration backup.

sudo gitlab-ctl reconfigure

2. GitLab Application Backup

GitLab application backup creates a backup for the following items:

  1. Database
  2. Attachments
  3. Git repositories data
  4. CI/CD job output logs
  5. CI/CD job artifacts
  6. LFS objects
  7. Container Registry images
  8. GitLab Pages content

GitLab application backup is created separately in /var/opt/gitlab/backups/.

You can use the following command to create application backup:

# sudo gitlab-backup create

Daily Backup

In order to create daily backup, run following command:

# sudo crontab -e -u root
0 2 * * * /opt/gitlab/bin/gitlab-backup create CRON=1

The daily backup will be created every day at 02:00 AM.

Restore from Backup

To restore the backup, you need to stop GitLab by using the following commands:

sudo gitlab-ctl stop unicorn
sudo gitlab-ctl stop puma
sudo gitlab-ctl stop sidekiq
# Verify
sudo gitlab-ctl status

The default user created by GitLab is named as ‘git’. If you want to restore from backup change the ownership of the backup file located in /var/opt/gitlab/backups/ to the user ‘git’ by using the following command:

# sudo chown git:git /var/opt/gitlab/backups/11493107454_2018_04_25_10.6.4-ce_gitlab_backup.tar

Next, use the following command to restore a backup for GitLab:

# This command will overwrite the contents of your GitLab database!
sudo gitlab-backup restore BACKUP=1493107454_2018_04_25_10.6.4-ce

Once the backup is restored, reconfigure GitLab server:

sudo gitlab-ctl reconfigure
sudo gitlab-ctl restart
# Verify
sudo gitlab-rake gitlab:check SANITIZE=true

The last command, gitlab-rake gitlab:check SANITIZE=true will help us to verify if everything went smoothly or not.

Exit mobile version