一 备份gitlab为完整压缩包
# 在目录/var/opt/gitlab/backups/ 创建备份文件
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
二 恢复gitlab
复制gitlab_backup.tar到对应备份目录下
1 将备份文件权限修改为777
chmod 777 1559614181_2019_06_04_10.7.7_gitlab_backup.tar
2 停止相关数据连接服务
gitlab-ctl stop unicorn
gitlab-ctl stop sidekiq
3 执行命令从备份文件中恢复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 设置定时备份
编辑文件 /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 设置备份过期时间
设置只保存最近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
创建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 建立计划任务,定时运行脚本
见 设定Windows任务 https://www.jb51.net/article/131471.htm
参考资料
git学习------> Gitlab如何进行备份恢复与迁移?
https://blog.csdn.net/ouyang_peng/article/details/77070977
ftp、sftp利用bat脚本自动下载以及上传文件
https://blog.csdn.net/maimai1993/article/details/79171674