!/bin/bash
gitlab server backup path
LocalBackDir=/var/opt/gitlab/backups
Remote backup server backup file storage path gitlab
RemoteBackDir=/root/gitlab_backup
Remote backup server login account
RemoteUser=root
Remote backup server IP address
RemoteIP = (B backup server's address, please amend its own)
The current system date
DATE=date +"%Y-%m-%d"
Log storage path
LogFile=$LocalBackDir/log/$DATE.log
Find a local backup directory under gitlab time of 60 minutes, and the suffix .tar backup file of gitlab
BACKUPFILE_SEND_TO_REMOTE=$(find $LocalBackDir -type f -mmin -60 -name '.tar')
New Log Files
touch $LogFile
Append log to a 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 a remote server
scp $BACKUPFILE_SEND_TO_REMOTE $RemoteUser@$RemoteIP:$RemoteBackDir
Append log to a log file
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