How to back up & restore a gitlab runner?

I have a gitlab runner on a small Linux box. I need to reinstall the OS on that box, and I’d like to not have to set up the gitlab runner from scratch after the reinstall. (I’m using the SaaS for my repo and CI, not my own instance.) What config files etc. do I need to back up and restore to keep my same gitlab runner working?

Hi @garyo

This depends a little on how you have set up your runners.

You probably have a home directory for the gitlab-runner user and that will need to be backed up.

If all your config.toml files are in /home/gitlab-runner/.gitlab-runner/ then that might be all you need, but you will likely also want the systemd config file, which is at /etc/systemd/system/gitlab-runner.service on Ubuntu.

You should certainly check gitlab-runner.service because it may point to config.toml files elsewhere, and if you have created any runner configs in different locations, then these also need to be backed up (otherwise you will need to re-create your runners from scratch).

Other files will be less important, but if you want to also save the intermediate results of pipelines that have finished, then again, that depends how you’ve set up your server, but if you just have one user for the runners, and you haven’t changed the default configurations, then you may just need the home directory.

Also, if you have other directories around your system that are owned by the gitlab-runner user, you may want to back them up.



1 Like

On Debian, under /etc/gitlab-runner there is a config.toml that could have your initial gitlab-runner configuration after installing the package. Chances are your token which allowed you to connect it to your gitlab instance will be on this config.toml file and thus you’ll need to take a copy of that. Restoring should then just be a case of installing the gitlab-runner package, putting the files back in the appropriate place and then starting the runner - in addition to the /home/gitlab-runner that @snim2 mentioned.

My default /etc/systemd/system/gitlab-runner.service file after a basic install from deb packages:

root@gitlab-runner:/home/gitlab-runner# cat /etc/systemd/system/gitlab-runner.service 
Description=GitLab Runner

ExecStart=/usr/bin/gitlab-runner "run" "--working-directory" "/home/gitlab-runner" "--config" "/etc/gitlab-runner/config.toml" "--service" "gitlab-runner" "--user" "gitlab-runner"


I’ve removed unnecessary spacing between config items to keep it concise here in the post without taking up too much space. You can check/verify that against your gitlab-runner.service systemd script.

1 Like