Gitlab備份到windows、在Linux恢復(fù)

一 備份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可運行psftp.exe

3.2 建立psftp配置文件和下載腳本

E:\85gitlab_backup創(chuàng)建2個文件:sftp.txtgitlab_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ù),定時運行腳本

見 設(shè)定Windows任務(wù) https://www.jb51.net/article/131471.htm


參考資料
git學(xué)習(xí)------> Gitlab如何進行備份恢復(fù)與遷移?
https://blog.csdn.net/ouyang_peng/article/details/77070977
ftp、sftp利用bat腳本自動下載以及上傳文件
https://blog.csdn.net/maimai1993/article/details/79171674

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

友情鏈接更多精彩內(nèi)容