DEV Community

Frederick Ollinger
Frederick Ollinger

Posted on

Gitlab Server Restore Tutorial

This post allows you to restore Gitlab backups which were made in this post: https://dev.to/frederickollinger/gitlab-server-backup-howto-4l7c

It's required that you make a backup before you restore it.

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.

Just like the backup article, we will use /mnt/gitlab/backups as our backup directory. If this is different, then set the variable BACKUPDIR accordingly.

BACKUPDIR=/mnt/gitlab/backups
BACKUPFILE=`ls -t | grep _gitlab_backup.tar | head -1 | sed 's/_gitlab_backup.tar//g'`
Enter fullscreen mode Exit fullscreen mode

For a restore to work properly, we need to change user and group ownership to git.

chown git.git ${BACKUPDIR}/*gitlab_backup.tar
Enter fullscreen mode Exit fullscreen mode

Need to stop some services so we are not writing and restoring at the same time:

sudo gitlab-ctl stop unicorn
sudo gitlab-ctl stop sidekiq
Enter fullscreen mode Exit fullscreen mode

Now we do the actual restore:

GITLAB_ASSUME_YES=1 /usr/bin/gitlab-backup restore BACKUP=${BACKUPFILE}
Enter fullscreen mode Exit fullscreen mode

Secrets are not restored via gitlab-backup restore (go figure):

cp ${BACKUPDIR}/gitlab-secrets.json /etc/gitlab
Enter fullscreen mode Exit fullscreen mode

OPTIONAL: If you are not going to reconfigure from scratch, you need to restore the configuration file. (I don't do this step as I dynamically generate the config script):

cp ${BACKUPDIR}/gitlab.rb /etc/gitlab
Enter fullscreen mode Exit fullscreen mode

IMPORTANT: Restart the services we stopped and allow things to get reconfigured post-restore:

/usr/bin/gitlab-ctl restart
Enter fullscreen mode Exit fullscreen mode

That's it. Go to the hostname in your browser of where your Gitlab Server is running and ensure that your repositories are back.

Top comments (0)