Is your GitLab backup configuration set up properly?
This bit is crucial because your GitLab server gets updated with new data every day, increasing the chances of a potential server crash due to various reasons.
Moreover, these regular updates can be pretty frustrating. Your servers create heaps of data and you might lose some of it. That’s why it’s important to configure your GitLab backups correctly because they are critical to maintain your application and keep your data intact.
GitLab Backup Configuration Best Practices
Configuring your GitLab backup is a must regardless of how tedious the process can be. Doing so helps you keep track of your repositories and saves you from any unexpected server crashes.
Below are some of the best practices when configuring your GitLab backup.
1. Creating a Backup of Omnibus-GitLab Configuration
To prevent any data losses, secure a copy of the /etc/gitlab directory. Ensure you have a copy of these two essential files:
- The file containing configuration parameters of your application, I.e., /etc/gitlab/gitlab.rb.
- The file containing database encryption keys protects sensitive data in SQL database, I.e., /etc/gitlab/gitlab-secrets.json.
2. Creating a GitLab System Backup
You can use GitLab’s command-line interface to back up the whole system. It includes the following instances:
- Database
- Attachments
- Git repositories
- GitLab pages content
- Snippets
- Group wikis
- LFS objects
- CI/CD job artifacts
- CI/CD job output logs
- Container Registry images
Use this command to create a backup system:
sudo gitlab-rake gitlab:backup:create
You’ll find the backup stored in the /var/opt/gitlab/backups directory.
3. Creating Daily Backups
Another way to protect your GitLab configuration is to run daily backups. You can achieve this by editing the cron table for user root.
sudo crontab -e -u root
In the cron table, create a tar file with the contents of /etc/gitlab/ using a command such as this:
15 04 * * 2-6 gitlab-ctl backup-etc && cd /etc/gitlab/config_backup && cp $(ls -t | head -n1) /secret/gitlab/backups/
GitLab Backup Configuration Dos and Don’ts
For a seamless backup process, learn what you should (and should not) do while setting up your GitLab backup configuration.
Let’s take a look at some key points you should consider before a backup.
Dos
Run Multiple Backups
Backup daily, weekly, and monthly to ensure you don’t lose any data if one of your backups fails. Accessing and restoring files is also easier when you have more than one backup.
Keep yourself updated with the process
Keep an eye on the backup process to make sure it is running properly. You can do this by setting up automated confirmation emails that deliver once after every completed backup process.
Don’ts
Keeping backups solely on GitLab’s server
Storing your backups on the GitLab server itself is risky. If an unexpected crash occurs, you’ll lose all (or some) of your data.
Avoid doing your GitLab backups manually
If you don’t backup your GitLab data automatically, there’s a good chance you’ll forget to run your backups. After all, it’s easy to overlook running the backups when you have truckloads of things on your list of to-dos.
Automated Workflow for GitLab Backups
While maintaining GitLab backups is essential, the whole process can also be time-consuming, making it an absolute must for companies to use an automated workflow for GitLab backups.
You can do this through cron-based backups or by using Backrightup.
Using Cron Jobs for backup
A cron job is a time-based scheduler that allows you to run recurring backups in regular intervals.
Below are several ways on how to configure GitLab backups and create automated backups using Cron Jobs to prevent any loss of essential files and older versions of your applications.
For Omnibus GitLab packages
1. First, you need to edit the crontab for a root user.
sudo su –
crontab -e
2. Use this command to schedule a backup at a certain time, say, 2 am.
0 2 * * * /opt/gitlab/bin/gitlab-backup create CRON=1
For installations from source
1. Edit the crontab for the Git user.
sudo -u git
crontab -e
2. Use the following commands and add them to the code. This will schedule your backup for a specific time every 24 hours.
# Create a full backup of the GitLab repositories and SQL database every day at 2 am
0 2 * * * cd /home/git/gitlab && PATH=/usr/local/bin:/usr/bin:/bin bundle exec rake gitlab:backup:create RAILS_ENV=production CRON=1
Using Backrightup
A better way to simplify and streamline your application maintenance is by running automated GitLab configuration backups through Backrightup.
Here’s how you can create backups using our platform.
1. Sign up then log in to your account.
2. The software starts backing up your GitLab configurations as soon as you log in.
3. Click the Backrightup option on the interface.
4. On the left side, you’ll find a list of options containing GitLab repositories and other items. You can view your backups from there.
5. You can also go to Settings > Repository Settings and enable backups and other items by clicking the “Yes” button.
6. Restore updated items by clicking the Restore Items option at the top of the table.
Automating your GitLab backups is the best way to manage repositories and other important files without manual work and with minimal data loss risks.
Set up GitLab Backup Configuration
It is crucial to set up a GitLab backup configuration as a Git user to maintain proper file permission and maintenance.
Use the backup script below to run successful data backups. You can create this under the GitLab installation in the “/home/git/gitlab/tmp/backups” folder.
root@linoxide:/home/git/gitlab# sudo -u git -H bundle exec rake gitlab:backup:create RAILS_ENV=production
Dumping database …
Dumping PostgreSQL database gitlabhq_production … [DONE]
done
Dumping repositories …
done
Dumping uploads …
done
Creating backup archive: 1479023906_gitlab_backup.tar … done
Deleting tmp directories … done
Deleting old backups … skipping
root@linoxide:/home/git/gitlab/tmp/backups# ll
total 68
drwxr-xr-x 2 git git 4096 Nov 13 07:58 ./
drwxr-xr-x 7 git git 4096 Nov 13 07:58 ../
-rw-r–r– 1 git git 61440 Nov 13 07:58 1479023906_gitlab_backup.tar
Backup the entire GitLab backup configuration folder to keep your data safe.
Use this script and save it in the GitLab backup folder “/home/git/gitlab/tmp/backups/config-backups/”
#!/bin/sh
umask 0077;
cd /home/git/gitlab/
tar -czf /home/git/gitlab/tmp/backups/config-backups/config.$(date +%s).tgz config
Ready to set up your GitLab Backup configuration?
The tips in this guide are some of the easiest ways to configure GitLab backups and save your data files from potential crashes.
Leverage Backrightup. It ensures automated, safe, and convenient backups for your GitLab workflow and repositories.