- docker
- gitlab
- crontab
- rsync
- sshpass
文件层级关系
- /home
- deployment
- backup.sh
- sync.sh
- restore.sh
backup.sh
# 创建备份
gitlab-rake gitlab:backup:create
# 获取最新备份的文件名
backupName=$(ls -lt /home/gitlab/backup | grep gitlab_backup.tar | head -n 1 |awk '{print $9}');
# 获取文件名的前28位
backupName=${backupName:0:28}
# 调用同步脚本
sh /home/deployment/sync.sh $backupName
# 调用恢复脚本
sh /home/deployment/restore.sh $backupName
sync.sh
# 同步到云
# 备份文件名
backupName=$1
sshpass -p "密码" rsync --progress "/home/gitlab/backup/"$backupName"_gitlab_backup.tar" root@服务器ip:"/root/gitlab/"$backupName"_gitlab_backup.tar"
restore.sh
# 备份名称 例:backupName="1590975087_2020_06_01_11.9.8";
backupName=$1;
# 备份文件全名
backupFullName=$backupName"_gitlab_backup.tar"
# 复制到目录文件下
cp "/home/gitlab/backup/"$backupFullName /home/deployment/gitlab/data/backups/
# 设置权限
chmod 777 "/home/deployment/gitlab/data/backups/"$backupFullName
# 执行恢复
yes yes|docker exec -i gitlab gitlab-rake gitlab:backup:restore BACKUP=""$backupName
crontab
# 编辑
crontab -e
# 每天 23:00 执行
00 23 * * * /bin/sh /home/deployment/backup.sh
# 查看
crontab -l
# 重启 crontab
/bin/systemctl restart crond.service
工作示意图
- GitLab [宿主机]
- ⌚23:00调用
backup.sh
restore.sh
本地备份并恢复到docker备用gitlab上
sync.sh
同步指定服务器
原文地址:https://www.cnblogs.com/linyisonger/p/13367794.html
参考文章地址:https://www.cnblogs.com/ssgeek/p/9392104.html