gitlab自动备份脚本auto_backup_to_remote

#!/bin/bash

# gitlab 服务器备份路径
LocalBackDir=/var/opt/gitlab/backups

# 远程备份服务器 gitlab备份文件存放路径
RemoteBackDir=/root/gitlab_backup

# 远程备份服务器 登录账户
RemoteUser=root

# 远程备份服务器 IP地址
RemoteIP=(备份服务器B的地址,请你自行修改)

#当前系统日期
DATE=`date +"%Y-%m-%d"`

#Log存放路径
LogFile=$LocalBackDir/log/$DATE.log

# 查找 gitlab本地备份目录下 时间为60分钟之内的,并且后缀为.tar的gitlab备份文件
BACKUPFILE_SEND_TO_REMOTE=$(find $LocalBackDir -type f -mmin -60  -name '*.tar*')

#新建日志文件
touch $LogFile

#追加日志到日志文件
echo "Gitlab auto backup to remote server, start at  $(date +"%Y-%m-%d %H:%M:%S")" >>  $LogFile
echo "---------------------------------------------------------------------------" >> $LogFile

# 输出日志,打印出每次scp的文件名
echo "---------------------The file to scp to remote server is: $BACKUPFILE_SEND_TO_REMOTE-------------------------------" >> $LogFile


#备份到远程服务器
scp $BACKUPFILE_SEND_TO_REMOTE $RemoteUser@$RemoteIP:$RemoteBackDir

#追加日志到日志文件
echo "---------------------------------------------------------------------------" >> $LogFile

脚本

#!/bin/bash
#gitlab bakup_directory
LocalBackDir=/var/opt/gitlab/backups
#remote bakup_directory
RemoteBackDir=/root/gitlab_backup
#remote USER
RemoteUser=root
#remote IP
RemoteIP=192.168.4.64
#date
DATE=`date +"%Y-%m-%d"`
#log directory
LogFile=$LocalBackDir/log/$DATE.log
#Find the gitlab backup file with the suffix of .tar in the gitlab local backup directory for 60 minutes.
BACKUPFILE_SEND_TO_REMOTE=$(find $LocalBackDir -type f -mmin -60  -name '*.tar*')
#New log file
touch $LogFile
#Append log to log file
echo "Gitlab auto backup to remote server, start at  $(date +"%Y-%m-%d %H:%M:%S")" >>  $LogFile
echo "---------------------------------------------------------------------------" >> $LogFile
#Output log, print out the file name of each scp
echo "---------------------The file to scp to remote server is: $BACKUPFILE_SEND_TO_REMOTE-------------------------------" >> $LogFile
#backup to remote server
scp $BACKUPFILE_SEND_TO_REMOTE $RemoteUser@$RemoteIP:$RemoteBackDir
#Append log to log file
echo "---------------------------------------------------------------------------" >> $LogFile
posted @ 2019-12-23 17:38  Doc-Yu  阅读(369)  评论(0编辑  收藏  举报