标签:cront local pre %s 服务器端 备份服务器 user 计划 exe
gitlab机器编写sh[root@gitlab ~]# vim auto_backup_to_remote.sh
LocalBackDir=/var/opt/gitlab/backups # gitlab备份文件目录
RemoteBackDir=/root/gitlab_backup # 远程的备份目录
RemoteUser=root # 远程服务器用户
RemotePort=22 # 远程服务器端口
RemoteIP=192.168.3.3 # 远程备份的服务器IP
DATE=`date +"%Y-%m-%d"` # 输出当日时间
LogFile=$LocalBackDir/log/$DATE.log # 日志文件
BACKUPFILE_SEND_TO_REMOTE=$(find /var/opt/gitlab/backups/ -type f -mmin -60 -name ‘*.tar*‘) # 找到gitlab 60分钟内备份生成的文件
touch $LogFile
echo "Gitlab auto backup to remote server, start at $(date +"%Y-%m-%d %H:%M:%S")" >> $LogFile
echo "---------------------------------------------------------------------------" >> $LogFile
scp -P $RemotePort $BACKUPFILE_SEND_TO_REMOTE $RemoteUser@$RemoteIP:$RemoteBackDir
echo "---------------------------------------------------------------------------" >> $LogFile
写计划任务
[root@gitlab ~]# crontab -l
30 12 * * * gitlab-rake gitlab:backup:create
30 23 * * * gitlab-rake gitlab:backup:create
40 12 * * * /root/auto_backup_to_remote.sh
40 23 * * * /root/auto_backup_to_remote.sh
登录gitlab备份机器192.168.3.3
[root@gitbackup ~]# vim auto_remove_old_backup.sh
#!/bin/bash
# 远程备份服务器 gitlab备份文件存放路径
GitlabBackDir1=/root/gitlab_backup
# 查找远程备份路径下,超过14天且文件后缀为.tar 的 Gitlab备份文件 然后删除
find $GitlabBackDir1 -type f -mtime +14 -name ‘*.tar*‘ -exec rm {} \;
标签:cront local pre %s 服务器端 备份服务器 user 计划 exe
原文地址:https://blog.51cto.com/14051712/2403002