gitlabコードバックアップ
1463 ワード
gitlabマシン作成sh
計画タスクの書き込み
gitlabバックアップマシンにログイン192.168.3.3
[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 {} \;