svn在目前项目中用的比较少了,但是还是有些老项目会用,这里分享一个备份脚本
文件名:svn_backup.sh
路径:/data/backups/script
脚本说明:
1.保留最近7天备份,多余自动删除
2.采用svnadmin hotcopy全量备份
3.备份成功会调用文件传输脚本,把备份文件传输到备份机器
#!/bin/bash datetime=`date +%Y%m%d-%H-%M-%S` OneWeekAgo=`date -d "1 week ago" +%Y%m%d` basePath=/data/backups/svn bakFilePath=$basePath/$datetime delFile=$basePath/$OneWeekAgo* logfile=$basePath/full_$datetime.log delLogFile=$basePath/full_$OneWeekAgo*.log mkdir -p $bakFilePath pid=`ps -ef | grep -v "grep" |grep -i 'svnadmin hotcopy'|awk '{print $2}'|head -n 1` if [ -z $pid ] then echo " start full backup svn " >> $logfile /usr/bin/svnadmin hotcopy /opt/svn/ $bakFilePath >> $logfile 2>&1 if [ $? -eq 0 ];then echo 'backup success,delete expired backup ' $delFile >> $logfile rm -rf $delFile rm -f $delLogFile sh /data/backups/script/rsync.sh $logfile else echo "backup failure,no delete expired backup" >> $logfile fi else echo "****** svn in backup ****** " >> $logfile fi
文件传输脚本:rsync.sh
路径:/data/backups/script
#!/bin/bash datetime=`date +%Y%m%d-%H-%M-%S` logfile=$1 echo "$datetime Rsync backup start " >> $logfile rsync -e "ssh -p22" -avpgolr --delete /data/backups bigtree@10.30.30.6:/data/backup_data/bigtree/10.30.30.12/ >> $logfile 2>&1 ret=`tail -n 1 $logfile |grep "total size"|wc -l` if [ "$ret" = 1 ] ; then echo "$datetime Rsync backup gitlab finish " >> $logfile else echo "$datetime Rsync backup failure ,pls sendmail" >> $logfile fi
crontab 任务:每天晚上3点备份
0 3 * * * /bin/bash -x /data/backups/script/svn_backup.sh > /data/backups/svn/cron.log 2>&1
参考文档:
https://www.cnblogs.com/xkops/p/5457932.html
https://www.jianshu.com/p/95541ec7f2a8