svn批量備份還原腳本

上週備份SVN時,順手瞎寫了批量備份及還原的腳本,測試ubuntu下可正常應用,分開為兩腳本。這兩腳本只能在所有SVN庫位於同於目錄下才可用,運行備份腳本時,若非第一次,會刪除所有已存在的.dump文件<自訂>。還原腳本亦會檢查指定目錄中存在的與欲還原的SVN同名的所有庫。

備份

#!/bin/bash
svnDir=$1
tmpFile=/tmp/svndump.txt
dump (){
echo "######Start dumpping   $i !######"
echo ""
sleep 2
svnadmin dump $i > $i.dump     #Start dumpping process !

if  [ -e "$i".dump ];   then  #Chek dumpped file !

echo "$i done completed !"
echo ""

else

echo "$i dump failed !"
echo ""

fi
}

usage () {

echo ""
echo "Specify the svn repos parentpath !"
echo ""
}

if [ "$1" = ""  ]; then   #Check if SVN repos parent path specified !

usage

else if [ ! -e "$1"  ]  ;then  #Check if SVN repos parent path exist !

echo ""
echo "$1 does not exist !"
else

ls -d $svnDir*/ |sed 's/.$//' > $tmpFile  #Get SVN repos directory to $tmpFile !

for i in `cat $tmpFile `   #Get SVN repos directory from $tmpFile !

do

if [ ! -e "$i".dump ];then  #Check exist dump file !

echo "Now start dumpping !"
sleep 1
dump

else if [ -e "$i".dump ]; then  #Check exist dump file !

echo "Removing $i.dump !"
sleep 1
rm -rf $i.dump
sleep 1
dump

fi

fi

donerm -rf $tmpFile

fi

fi

 

還原
#!/bin/bash
svnDir=$1
tmpFile=/tmp/svndump.txt
load () {echo "Creating $i"
sleep 1
svnadmin create  $i
echo "####Loading  $i !"
sleep 2
svnadmin load $i < $i.dump
if [ -e "$i" ];     then

echo "$i restore completed !"
echo ""
else

echo "$i restore failed !"
echo ""
fi

}

usage () {

echo "Specify the svn repos parentpath !"

}

if [ "$1" = ""  ]; then

usage

else if [ ! -e "$1" ];then

echo "$1 does not exist !"

else

ls -d $svnDir*.dump | sed 's/.dump$//' > $tmpFile

for i in `cat $tmpFile `

do

if [ ! -e "$i" ];then

echo "Now Start loading !"
sleep 1
load

else if [ -e "$i" ];then

echo "Removing $i"
sleep 1
rm -rf $i
echo "Now start loading !"
sleep 1
load

fi

fi

done

rm -rf $tmpFile

fi

fi

 

发表评论

电子邮件地址不会被公开。 必填项已用*标注