GitLab 自动化备份方案:借助 Shell 脚本与 Cron 实现异地备份和备份清理
通过编写 Shell 脚本,用户可以实现每日异地备份,并自动删除大于 7 天的过期备份。借助 Cron 定时任务功能,每天凌晨 2 点自动触发备份操作,确保数据安全和备份的高效管理。
·
#!/bin/bash
#使用gitlab自带命令创建备份
gitlab-rake gitlab:backup:create
#将最新的备份做异地策略
scp $(find /var/opt/gitlab/backups -name "*.tar" -type f -exec ls -lt {} + | head -1 | awk '{print $NF}' ) root@192.168.1.33:/backup/gitlab/backup
#删除7天之前的备份
find "/var/opt/gitlab/backups" -name "*.tar" -ctime +7 -type f -exec rm -rf {} \;
再配合定时任务可完成每日备份并将最新的备份文件异地存储,同时删除大于7天的老备份文件
[root@localhost backups]# crontab -l
0 2 * * * /opt/gitbak.sh >> /var/log/gitbak.log 2>&1
每日凌晨2点备份
更多推荐




所有评论(0)