Every day data keeps adding to your GitLab application’s production server and all is working fine. But you don’t realize that your server can crash due to a lot of reasons and sometimes by the time you realize all your data is lost. So, taking backup of your applications is as important as adding new features to them and it should be a part of maintaining your application.
Manually taking repeatedly backups sometimes becomes too boring. So, automating the whole process of taking the backup of your GitLab repositories is a good idea. But the smart approach is to keep your backup archive in Amazon S3 bucket rather than gitlab server itself or in any other local repository server because if server crashes then your backups are lost too.
Creating Gitlab Backup :
A backup creates an archive file that contains the database, all repositories and all attachments. The filename will be [TIMESTAMP]_gitlab_backup.tar . To create backup use the following command if you’ve installed GitLab with the Omnibus package :-
1 2 |
sudo gitlab-rake gitlab:backup:create |
Backup archive location :-
1 |
/var/opt/gitlab/backups/ |
Upload backups to cloud storage ( Amazon S3 bucket) :
For omnibus packages, make the following entries in /etc/gitlab/gitlab.rb file :-
1 2 3 4 5 6 7 8 9 10 11 12 |
gitlab_rails['manage_backup_path'] = true gitlab_rails['backup_path'] = "/var/opt/gitlab/backups" gitlab_rails['backup_archive_permissions'] = 0644 gitlab_rails['backup_pg_schema'] = 'public' gitlab_rails['backup_keep_time'] = 604800 # this may vary gitlab_rails['backup_upload_connection'] = { 'provider' => 'AWS', 'region' => 'us-west-2', # specify the region in which your bucket is created 'aws_access_key_id' => 'AdjkIAJFs2F3FYWRHXRd', # specify the access key of your IAM user 'aws_secret_access_key' => 'Mjfofiofipfojekjt4R+/IShmAC35WFdwdjw6Eof' # specify the secret access key of your IAM user } gitlab_rails['backup_upload_remote_directory'] = 'test-bucket' # your bucket name |
Next step is to reconfigure your gitlab after making these changes. Run the following command :-
1 |
gitlab-ctl reconfigure |
Setup Cron :-
Lets setup a cron job to create gitlab backup at 5 am everyday :-
1 2 |
0 5 * * * /usr/bin/gitlab-rake gitlab:backup:create |
Once you are done with the above mentioned gitlab configuration, this cron job will simply create a backup of your gitlab everyday at 5AM and sync that backup to your cloud storage location i.e. Amazon S3 bucket specified in gitlab.rb file. Therefore, you don’t have to bother about manually taking everyday backups and maintain a local repo server for storing those backups. Hope this helps !
Be the first to comment.