GitLab Backup and Restoration Guide

Automtaed GitLab Backups Using Cron

To automate GitLab backups, you can use cron jobs to execute backup scripts at scheduled intervals.

Schedule a Daily Backup

Edit the crontab file:

crontab -e

Add the following line to run a backup script daily at 2 AM:

0 2 * * * /opt/scripts/gitlab_backup.sh

Backup Script Content

The script should include commands to create a GitLab backup and synchronize it to a remote location:

# Create a GitLab backup
sudo gitlab-rake gitlab:backup:create

# Sync only current month's backup files (skip existing .tar files)
rsync -av --ignore-existing /var/opt/gitlab/backups/*$(date +\%Y_\%m)*.tar user@192.168.8.112:/data/backup/gitlab/

# Always sync the latest configuration files
rsync -av /etc/gitlab/gitlab.rb user@192.168.8.112:/data/backup/gitlab/
rsync -av /etc/gitlab/gitlab-secrets.json user@192.168.8.112:/data/backup/gitlab/

Alternatively, for a weekly full backup (e.g., every Sunday at midnight):

0 0 * * 0 /bin/bash -c '
sudo gitlab-rake gitlab:backup:create &&
scp /etc/gitlab/gitlab.rb user@192.168.8.112:/data/backup/gitlab/ &&
scp /etc/gitlab/gitlab-secrets.json user@192.168.8.112:/data/backup/gitlab/ &&
scp /var/opt/gitlab/backups/*$(date +\%Y_\%m)*.tar user@192.168.8.112:/data/backup/gitlab/
'

Installing GitLab CE 13.12.15

Download the Package

Obtain the correct version from the official repository:

GitLab CE 13.12.15 Packgaes

Install Dependencies and Package

sudo yum install -y curl openssh-server ca-certificates postfix git
sudo rpm -ivh gitlab-ce-13.12.15-ce.0.el7.x86_64.rpm --nodeps --force

Configure External URL

Edit /etc/gitlab/gitlab.rb:

external_url 'http://gitlab.haitang.local'

Apply Configuration

sudo gitlab-ctl reconfigure
sudo gitlab-ctl start
sudo gitlab-ctl status

Restoring a GitLab Backup

Stop Relevant Services

sudo gitlab-ctl stop puma
sudo gitlab-ctl stop sidekiq
sudo gitlab-ctl stop nginx

Copy Backup Archive

sudo cp /data/backup/gitlab/1751565890_2025_07_04_13.12.10-ee_gitlab_backup.tar /var/opt/gitlab/backups/

Restore Configuration Files

sudo cp /data/backup/gitlab/gitlab.rb /etc/gitlab/gitlab.rb
sudo cp /data/backup/gitlab/gitlab-secrets.json /etc/gitlab/gitlab-secrets.json

Perform Data Restoration

sudo gitlab-rake gitlab:backup:restore BACKUP=1751565890_2025_07_04_13.12.10-ee

Confirm with "yes" when prompted twice during the process.

Reconfigure and Restart

sudo gitlab-ctl reconfigure
sudo gitlab-ctl restart

If the server IP or domain has changed, update external_url in /etc/gitlab/gitlab.rb, then re-run:

sudo gitlab-ctl reconfigure
sudo gitlab-ctl restart

Verify Service Status

sudo gitlab-ctl status
netstat -tnlp | grep :80

Tags: gitlab Backup restore cron rsync

Posted on Tue, 30 Jun 2026 18:18:25 +0000 by carleyvibe