GitLab 自动化备份方案:借助 Shell 脚本与 Cron 实现异地备份和备份清理

#!/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}' ) [email protected]:/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点备份

你可能感兴趣的:(中间件,运维脚本,1024程序员节,运维,linux,gitlab)