備份哪些資料?

gitlab 上有哪些重要的資料是應該備份的呢?

  1. gitlab 設定檔
  2. 專案資料

備份 gitlab 設定檔

1
2
# 備份資料會放在 /var/opt/gitlab/backups
sudo sh -c 'umask 0077; tar -cf $(date "+/var/opt/gitlab/backups/gitlabconfig-%s.tar") -C / etc/gitlab'

備份 gitlab 專案

1
2
# 備份資料會放在 /var/opt/gitlab/backups.
/opt/gitlab/bin/gitlab-rake gitlab:backup:create

切換身份並設定排程

讓 linux 可以自動定時執行 script

1
2
3
4
# 切換身份執行
sudo crontab -e -u root
# 設定定時工作
15 04 * * 2-6 umask 0077; tar -cf $(date "+/var/opt/gitlab/backups/gitlabconfig-%s.tar") -C / etc/gitlab

同步資料夾到 NAS 中

1
2
3
4
5
#!/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 root@x.y.z.a:/root/backups/
echo "Backed up file /home/git/gitlab/tmp/backups/$fn to root@x.y.z.a.."

如何設定 SCP

如何設定 rsync

1
rsync -av /var/gitlabBackup/ username@10.1.1.31::IT\ Resources/gitlabBackup

上面的設定都免了直接設定 NFS 就好了,直接備份到 NFS 上

NFS 設定方式

NFS client

執行 mount

1
sudo mount 10.1.1.31:/volume1/NetBackup /mnt/

發生錯誤

1
2
3
4
5
6
mount: wrong fs type, bad option, bad superblock on 10.1.1.31:/volume1/NetBackup,
missing codepage or helper program, or other error
(for several filesystems (e.g. nfs, cifs) you might
need a /sbin/mount.<type> helper program)
In some cases useful info is found in syslog - try
dmesg | tail or so

原來是需要安裝 nfs 的套件

1
sudo apt-get install nfs-common

然後就可以掛載

1
sudo mount 10.1.1.31:/volume1/NetBackup gitlabBackup/

掛載前還需要先建立資料夾

1
mkdir gitlabBackup

結論

綜合以上的文獻資料,具體的作法:

  1. 先將 NAS 資料夾掛接到 Gitlab Server
  2. 透過 crontab 設定工作排程
  3. 完成