DEV Community

Frederick Ollinger
Frederick Ollinger

Posted on

Gitlab Server Backup Tutorial

Audience: Anyone who is actually running their own instance of Gitlab server. This person wants to ensure good backups and restore.

For this article, we'll cover only backups. This article was written with Ubuntu 20.04 with Gitlab version 15.0.0.

This article will tell you how to actually set up the required Gitlab server: https://linuxhint.com/installing_gitlab_ubuntu/

By the end of this, we'll be creating automated backups.

A good reference for this article is here: https://docs.gitlab.com/ee/raketasks/backup_restore.html

First step is to configure Gitlab.

Ensure backup path exists. Note that you can modify the path to your liking or keep the default. I used /mnt/gitlab/backups because I have an external backup drive mounted at /mnt/gitlab.

sudo mkdir -p /mnt/gitlab/backups
# Backup dir needs to be owned by user git so it
# can properly write backup files:
sudo chown git /mnt/gitlab/backups
Enter fullscreen mode Exit fullscreen mode

Edit the config file in /etc/gitlab/gitlab.rb:

# Change the backup path
gitlab_rails['manage_backup_path'] = true
gitlab_rails['backup_path'] = "/mnt/gitlab/backups"
# Limit the number of backups that we keep
gitlab_rails['backup_keep_time'] = 604800
Enter fullscreen mode Exit fullscreen mode

When done, save then reread the Gitlab configuration file:

 sudo gitlab-ctl reconfigure
Enter fullscreen mode Exit fullscreen mode

Next let's run out backup commands:

/usr/bin/gitlab-backup create force=yes GZIP_RSYNCABLE=yes STRATEGY=copy CRON=1
Enter fullscreen mode Exit fullscreen mode
  • force=yes will run without asking questions which is perfect for a script
  • GZIP_RSYNCABLE=yes To ensure the generated archive is transferable by rsync, you can set the GZIP_RSYNCABLE=yes option. This sets the --rsyncable option to gzip.
  • STRATEGY=copy The strategy copies data files to a temporary location before calling tar and gzip, avoiding potential errors if data changes while tar is reading it.
  • CRON=1 hides all progress output if there aren’t any errors

Next, we need to backup our secrets to the same location

cp /etc/gitlab/gitlab-secrets.json /etc/gitlab/gitlab.rb /mnt/gitlab/backups
Enter fullscreen mode Exit fullscreen mode

Now your Gitlab server is backed up, and it's possible to restore it.

Top comments (0)