Featured image of post Migration, Backup, and Restoration of GitLab Repositories

Migration, Backup, and Restoration of GitLab Repositories

Backing up and restoring repositories in GitLab is a crucial operation to ensure your data can be recovered in the event of unexpected failures. Here are the detailed steps for backing up and restoring...

Backing up and restoring repositories in GitLab is a vital operation that ensures your data can be recovered in case of unexpected failures.

Here are the specific steps for backing up and restoring GitLab repositories:

  1. Backing Up the GitLab Repository

There are two ways to back up data in GitLab: manual backup and automatic backup. Manual backup requires the use of GitLab’s command-line tools, while automatic backup involves configuring a backup strategy in GitLab’s settings.

For manual backups, you can use the following commands:

1
2
3
|  | For GitLab 12.2 and later, run: sudo gitlab-backup create |
| --- | --- |
|  | For GitLab 12.1 and earlier, run: sudo gitlab-rake gitlab:backup:create |

This command will back up the GitLab database and other data to the default backup storage location, /var/opt/gitlab/backups. If you want to specify a backup file name, you can use the -n parameter. For example:

1
sudo gitlab-rake gitlab:backup:create BACKUP=gitlab_backup_2023-05-14.tar
  1. Copying Backup Files to Another Host

Use the scp command or other file transfer tools to copy the backup file from the original host to the target host. For example:

1
scp /var/opt/gitlab/backups/gitlab_backup_2023-05-14.tar user@new_host:/tmp/
  1. Restoring GitLab Repository Data

On the target host, you need to prepare a GitLab environment that matches the version of the original host. Then, in the directory where the backup file is located, you can use the following command to restore:

1
2
3
|  | For GitLab 12.2 and later, run: sudo gitlab-backup restore BACKUP=11493107454_2018_04_25_10.6.4-ce |
| --- | --- |
|  | For GitLab 12.1 and earlier versions, run: sudo gitlab-rake gitlab:backup:restore BACKUP=gitlab_backup_2023-05-14.tar |

This command will extract the backup file and import the data into the GitLab environment on the target host.

  1. Verifying the Restored GitLab Repository

After restoring the GitLab repository data, you can use the following command to check if the imported data is correct:

1
sudo gitlab-rake gitlab:check SANITIZE=true

This command will check the GitLab database and Git repositories for any issues and output diagnostic information.

In summary, backing up and restoring GitLab repositories requires using GitLab command-line tools for manual backups or configuring automatic backups. After creating a backup, you need to transfer the backup file to another host and restore it using GitLab command-line tools. Once the restoration is complete, use the gitlab:check command to verify that the restored data is accurate.

Licensed under CC BY-NC-SA 4.0