#!/bin/bash
#created by xiaocong.wang on Aug 5th
############################
# create directory for backup
############################
today=`date +%Y%m%d%H%M`
budir=file$today
echo "===set the var to $today==="
echo "===set directory name to $budir==="
if [[ ! -d /home/backup ]];then
mkdir /home/backup
else
mkdir /home/backup/$budir
fi
###########################
# do the backup on local disk
###########################
echo "===backup start... pls waiting...===="
svnadmin hotcopy /opt/repos/ /home/backup/$budir && echo "===do the backup successfull===" /
|| echo "===backup error,pls do it again==="
##########################
# do the remote copy to SCM server
##########################
echo "===remote copy start... pls waiting...===="
scp -r /home/backup/$budir/* root@mgw-scm-server.china.nsn-net.net:/opt/repos/. && echo "===do remote copy successfull===" /
|| echo "===remote copy error,pls do it again==="
#########################
# clean 1 oldest archive while
# reaching 10 archives
#######################
file_num=`ls /home/backup | wc -l`
if [ $file_num -ge 10 ];then
echo -e "/n space full... starting cleaning files/n"
cd /home/backup
var1=`ls | awk 'NR==1' `
if [[ $var1 =~ "file*" ]] ; then
ls /home/backup | awk 'NR==1'| xargs rm -rf
echo -e "/n 1 archive deleted.../n"
else
echo -e "/n can NOT delete... pls double check before delete/n"
fi
else
echo -e "/n still have free space "
fi