码迷,mamicode.com
首页 > 其他好文 > 详细

gitlab自动备份脚本auto_backup_to_remote

时间:2019-12-23 19:12:27      阅读:201      评论:0      收藏:0      [点我收藏+]

标签:backup   echo   roo   tla   rem   nba   serve   oca   登录   

!/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

gitlab自动备份脚本auto_backup_to_remote

标签:backup   echo   roo   tla   rem   nba   serve   oca   登录   

原文地址:https://www.cnblogs.com/Doc-Yu/p/12085025.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!