Moon Light Box

Time is Money

GitLab - Backup and Restore

| Comments

For omnibus installations

Step1. Backup

# gitlab-rake gitlab:backup:create
# ls -lah /var/opt/gitlab/backups/

-rw-------.  1 git  git  980K Jun 16 18:33 1466073203_gitlab_backup.tar
-rw-------.  1 git  git  1.1M Jun 24 08:39 1466728758_gitlab_backup.tar
-rw-------.  1 git  git  1.6M Jul  6 08:53 1467766425_gitlab_backup.tar
-rw-------.  1 git  git  3.3M Jul 21 19:16 1469099786_gitlab_backup.tar
-rw-------.  1 git  git  4.8M Aug 11 17:36 1470908204_gitlab_backup.tar
-rw-------.  1 git  git  5.8M Aug 23 16:15 1471940158_gitlab_backup.tar
-rw-------.  1 git  git  7.1M Sep  2 18:10 1472811017_gitlab_backup.tar
-rw-------.  1 git  git  8.0M Sep 26 10:26 1474856772_gitlab_backup.tar
-rw-------.  1 git  git  9.3M Oct 14 17:54 1476438840_gitlab_backup.tar
-rw-------.  1 git  git  9.8M Oct 24 09:13 1477271599_gitlab_backup.tar
-rw-------.  1 git  git  4.2G Oct 28 14:24 1477635758_gitlab_backup.tar // Restore this backup

Step2. Change Backup Files Path

# vim /etc/gitlab/gitlab.rb
gitlab_rails['backup_path'] = "/var/opt/gitlab/backups" // This is default path. You can change it.

# gitlab-ctl reconfigure

Step3. Crontab

// Schedule the backup for everyday at 2 AM
// The CRON=1 environment setting tells the backup script to suppress all progress output if there are no errors. This is recommended to reduce cron spam.

# crontab -e
0 2 * * * /opt/gitlab/bin/gitlab-rake gitlab:backup:create CRON=1
0 3 * * * /usr/bin/scp /var/opt/gitlab/backups/*_gitlab_backup.tar BACKUP_SERVER_ACCOUNT@BACKUP_SERVER:~/gitlab_backups

Step4. Set SSH key

# ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
89:bd:c1:86:3e:f8:27:aa:b0:37:af:0f:e2:3b:a3:90 root@GitLab01
The key's randomart image is:
+--[ RSA 2048]----+
|                 |
|                 |
|                 |
|       = .       |
|      o S        |
| .   o . o       |
|E . . o .        |
|o*o. ....        |
|++**+..o         |
+-----------------+

# cat ~/.ssh/id_rsa.pub | ssh BACKUP_SERVER_ACCOUNT@BACKUP_SERVER "cat >> ~/.ssh/authorized_keys"

Step5. Set Backup Expire Time

# vim /etc/gitlab/gitlab.rb
gitlab_rails['backup_keep_time'] = 604800 // limit backup lifetime to 7 days - 604800 seconds

# gitlab-ctl reconfigure

Step6. Restore

# gitlab-ctl stop unicorn
# gitlab-ctl stop sidekiq
# gitlab-ctl status
# gitlab-rake gitlab:backup:restore BACKUP=1477635758
# gitlab-ctl start
# gitlab-rake gitlab:check SANITIZE=true

https://gitlab.com/gitlab-org/gitlab-ce/blob/master/doc/raketasks/backup_restore.md
http://gwokae.mewggle.com/wordpress/2010/08/%E8%B6%85%E6%98%93-%E5%85%A9%E8%A1%8C%E6%8C%87%E4%BB%A4%E6%90%9E%E5%AE%9A-linux-ssh%E7%99%BB%E5%85%A5%E5%85%8D%E5%AF%86%E7%A2%BC/
http://ascendbruce.logdown.com/posts/139004-backup-ubuntu-linux-and-upload-to-another-server

Comments

comments powered by Disqus