Backing up gitlab

[email protected]:/home/git/gitlab# sudo -u git -H rake RAILS_ENV=production gitlab:backup:create
Dumping database ...
done
Dumping repositories ...
 * root/bash-advanced-scripts ... [DONE]
 * root/perlscripts ... [DONE]
 * root/server-status-monitor ... [DONE]
 * root/dns-manager ... [DONE]
 * root/securessh ... [DONE]
 * root/wordpress_plugin_updater ... [DONE]
 * root/openvpn_installer ... [DONE]
 * root/utorrent-installer ... [DONE]
 * root/pinger ... [DONE]
done
Dumping uploads ...
done
Creating backup archive: 1384776583_gitlab_backup.tar ... done
Deleting tmp directories ... done
Deleting old backups ... skipping

The backups get stored in /home/git/gitlab/tmp/backups/

Now I will show a script which can backup your gitlab periodically to a remote server.

#!/usr/bin/bash
cd /home/git/gitlab
fn=`sudo -u git -H rake RAILS_ENV=production gitlab:backup:create | grep 'Creating backup archive:' | awk '{print $4}'`
scp /home/git/gitlab/tmp/backups/$fn [email protected]:/root/backups/
echo "Backed up file /home/git/gitlab/tmp/backups/$fn to [email protected]"

Here, replace -u git, where git should be replaced by the username of the gitlab installation (check /etc/passwd)

Add to crontab and be safe:

0 0 */2 * * /usr/bin /root/backupgitlab

As documented here, to create a backup:

sudo -u gitlab -H rake RAILS_ENV=production gitlab:backup:create

To restore from this:

sudo -u gitlab -H rake RAILS_ENV=production gitlab:backup:restore BACKUP=/home/gitlab/gitlab/tmp/backups/20130125_11h35_1359131740