Easy & simple guide to Backup & Restore GITLAB

Gitlab is a web GUI for git repositories with support for CI/CD, issue tracking & wiki. We have already discussed in detail, how we can install GITLAB on CentOS & Ubuntu systems. In this tutorial, we will discuss how we can backup & restore Gitlab.

When we initiate a Gitlab backup, it will create an archive that will contain the database, all the repositories & also all the attachments.

So why would we need to backup Gitlab?

Well it can be due to any of the following reasons, first & foremost should be that we don’t want to loose our data in case of server failure. Another major reason could be that we want to migrate our Gitlab server to another. If that’t the case than you should remember, that we can only restore a backup to same Gitlab version & type i.e. community edition or enterprise edition.

Recommended Read: How to install git on Linux

Also Read: Complete “Beginners to PRO” guide for GIT commands

Now, let’s start with process to backup & restore Gitlab .


Backup & Restore Gitlab


Taking a backup

Depending on how you have installed Gitlab on your system, there are different commands to take backup,

1- Omnibus installation – Now if you have followed the method mentioned in the tutorial HERE, than that will be omnibus installation & for taking the backup for gitlab installed this way, command would be,

$ sudo gitlab-rake gitlab:backup:create

2- Source Installation – If you have installed Gitllab on your server using the source package, than you must run the following command to create a backup file for your Gitlab installation,

$ sudo -u git -H bundle exec rake gitlab:backup:create RAILS_ENV=production

When command is executed the backup process will start,

Dumping database tables:

– Dumping table events… [DONE]

– Dumping table issues… [DONE]

– Dumping table keys… [DONE]

– Dumping table merge_requests… [DONE]

– Dumping table milestones… [DONE]

– Dumping table namespaces… [DONE]

– Dumping table notes… [DONE]

– Dumping table projects… [DONE]

– Dumping table protected_branches… [DONE]

– Dumping table schema_migrations… [DONE]

– Dumping table services… [DONE]

– Dumping table snippets… [DONE]

– Dumping table taggings… [DONE]

– Dumping table tags… [DONE]

– Dumping table users… [DONE]

– Dumping table users_projects… [DONE]

– Dumping table web_hooks… [DONE]

– Dumping table wikis… [DONE]

Dumping repositories:

– Dumping repository abcd… [DONE]

Creating backup archive: $TIMESTAMP_gitlab_backup.tar [DONE]

Deleting tmp directories…[DONE]

Deleting old backups… [SKIPPING]

When the backup is complete, an archive will be created in the backup directory mentioned in ‘config/gtilab.yml’ with the name ‘[TIMESTAMP]_gitlab_backup.tar’. Here TIMESTAMP tells about when the backup was taken & also the gitlab version.

Note:- Usually the backup directory is ‘/var/opt/gitlab/backups/’ by default.

 

Restoring a backup

As mentioned above, we need to have same version to be able to restore a backup & similar to taking backup, we have separate procedure for backup restoring for omnibus & source installation,

1- Omnibus installation- First we need to make sure that the backup tar file is in the backup directory described in the gitlab.rb configuration (Default is /var/opt/gitlab/backups). Next, we need gitlab running for restoring backup on ominbus installations. If it’s not up, start with,

$ sudo gitlab-ctl start

& we need to have services that are connected to database in stopped state,

$ sudo gitlab-ctl stop unicorn

$ sudo gitlab-ctl stop sidekiq

Now execute the following command to restore the backup on server,

$ sudo gitlab-rake gitlab:backup:restore BACKUP=1393157476_2018_03_11_9.1.0

here, 1393157476_2018_03_11_9.1.0 is the name of the backup file that will be restored. Once the backup has been restored, we need to restart the gitlab services,

$ sudo gitlab-ctl restart

We now have successfully restored gitlab from the backup file.

2- From source- For restoring backup on Gitlab that has been installed from source, we need to first stop the services connected to database,

$ sudo service gitlab stop

& execute the following command to restore the database,

$ bundle exec rake gitlab:backup:restore RAILS_ENV=production

Once the backup has been restored, restart the gitlab services,

$ sudo service gitlab restart

This completes our tutorial on how to take Backup & Restore Gitlab server. Please feel free to send in your questions or suggestions using the comment box below.

If you think we have helped you or just want to support us, please consider these :-

Connect to us: Facebook | Twitter | Google Plus

Donate us some of your hard earned money:

Linux TechLab is thankful for your continued support.

Shusain

Passionate about Linux & open source. Loves to learn, read & write about Linux as well as new technologies.

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *