Gitlab is a tool for managing git repositories on a centralized server. Sometimes due to some reasons system crashes and we lose our valuable data. Therefore it is necessary to take regular backups of the gitlab server. So in case of any emergency we should be able to restore gitlab server with the backup data as soon as possible. In this tutorial I will show you how to restore a gitlab server from gitlab backup.
Before restoring gitlab you must consider the following points.
- Gitlab backup directory is /var/opt/gitlab/backups . You must put your gitlab backup files in this directory.
- Gitlab backup file format should be “timestamp_gitlab_backup.tar”
- Example of valid gitlab backup file name is “1468787928_gitlab_backup.tar”. where 1468787928 is the timestamp.
- Owner of the backup file should be git.
- You should restore the backup to the proper version of gitlab. If you have taken the backup from gitlab version 7.7.2, you should use the backup in version 7.7.2. You should not try to restore the backup in other versions.
Restoring gitlab from backup
Put your backup file in /var/opt/gitlab/backups/ and change the ownership to git. To change the ownership, run the following command.
1 |
chown -R git:git /var/opt/gitlab/backups |
I have already put the back up file in /var/opt/gitlab/backups/
To restore a gitlab back up, run the following command.
1 |
gitlab-rake gitlab:backup:restore 1468787928_gitlab_backup.tar |
Sometimes you can get this error. To resolve this error you must increase the RAM of your system and try again.
At last it will ask for rebuild an authorized_keys file. Select “no”.
Now, you have successfully restored your gitlab from the backup.
Suppose your backup filename is backup.tar. In this case you can not restore your data. Don’t worry, you have to only change the name to proper format. All you have to do is to get the exact timestamp of backup file.
Extract your backup file and read the backup_information.yml file.
backup_information.yml file is generally contains the following.
1 2 3 4 |
:db_version: '20150116234544' :backup_created_at: 2016-07-17 20:38:48.840076422 +00:00 :gitlab_version: 7.7.2 :tar_version: tar (GNU tar) 1.27.1 |
Now, you know when the backup was created. You need to generate the timestamp from these details.You need to focus the line backup_created_at. For generating timestamp go to http://www.timestampgenerator.com/
Enter all the details.
After you click on generate, it will show you the timestamp of the backup file.
So I should rename my file to 1468701528_gitlab_backup.tar
1 |
mv backup.tar 1468701528_gitlab_backup.tar |
Now, the name is in proper format. You can able to restore your gitlab from the backup.
If you have any doubts regarding restoration of gitlab backup, you can ask me in the comment.