一 備份gitlab為完整壓縮包
# 在目錄/var/opt/gitlab/backups/ 創(chuàng)建備份文件
gitlab-rake gitlab:backup:create
/var/opt/gitlab/backups/
1559614181_2019_06_04_10.7.7_gitlab_backup.tar
查看備份文件夾容量
df -h /var/opt/gitlab/backups
二 恢復(fù)gitlab
復(fù)制gitlab_backup.tar到對應(yīng)備份目錄下
1 將備份文件權(quán)限修改為777
chmod 777 1559614181_2019_06_04_10.7.7_gitlab_backup.tar
2 停止相關(guān)數(shù)據(jù)連接服務(wù)
gitlab-ctl stop unicorn
gitlab-ctl stop sidekiq
3 執(zhí)行命令從備份文件中恢復(fù)Gitlab
gitlab-rake gitlab:backup:restore BACKUP=備份文件編號
gitlab-rake gitlab:backup:restore BACKUP=1559614181_2019_06_04_10.7.7
輸入2次yes
4 啟動Gitlab
sudo gitlab-ctl start
三 定時備份Linux文件到windows
1 設(shè)置定時備份
編輯文件 /etc/crontab 最后一行加入眷蜓,記得加用戶名
# Example of job definition:
# .---------------- minute (0 - 59)
# | .------------- hour (0 - 23)
# | | .---------- day of month (1 - 31)
# | | | .------- month (1 - 12) OR jan,feb,mar,apr ...
# | | | | .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
# | | | | |
# * * * * * user-name command to be executed
0 2 * * 6 root /opt/gitlab/bin/gitlab-rake gitlab:backup:create CRON=1
每周六2點员魏,新備份文件會存于備份文件夾 /var/opt/gitlab/backups/
2 設(shè)置備份過期時間
設(shè)置只保存最近7天的備份誓沸,編輯 /etc/gitlab/gitlab.rb
gitlab_rails['backup_keep_time'] = 604800
sudo gitlab-ctl reconfigure
3 Windows下用sftp+腳本自動下載Linux備份文件夾
3.1 windows安裝putty
在http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html
下載putty工具包putty-64bit-0.71-installer.msi
诸迟,在win安裝,則cmd可運(yùn)行psftp.exe
3.2 建立psftp配置文件和下載腳本
在E:\85gitlab_backup
創(chuàng)建2個文件:sftp.txt
和gitlab_backup.bat
sftp.txt
lcd E:/85gitlab_backup
get -r /var/opt/gitlab/backups
bye
gitlab_backup.bat
@echo off
psftp 192.168.0.85 -l root -pw root -b "E:/85gitlab_backup/sftp.txt"
3.3 建立計劃任務(wù)汉矿,定時運(yùn)行腳本
見 設(shè)定Windows任務(wù) https://www.jb51.net/article/131471.htm
參考資料
git學(xué)習(xí)------> Gitlab如何進(jìn)行備份恢復(fù)與遷移崎坊?
https://blog.csdn.net/ouyang_peng/article/details/77070977
ftp、sftp利用bat腳本自動下載以及上傳文件
https://blog.csdn.net/maimai1993/article/details/79171674