SVN full backup and incremental backup scripts

SVN full backup and incremental backup scripts

SVN full backup and incremental backup scripts

 

SVN is powerful subversion system. most of the origination uses this system between development system and production system. Once Updated file or data reflected without Error and work properly. then we have to Update Code on production server.

Full backup scripts: schedule  this scripts every Saturday.

#!/bin/bash
#written by vikas kushwaha@knowledgelinux.com
#Edit your reportting mail address
EMail_Addr=report@knowledgelinux.com

ls -1tr /var/www/svn/ >/repolist.txt
{ while IFS=';' read reponame
do

DATE=`date "+%d%b%y"`
echo $reponame
backup_path=/svnbackup-all
LOG=$backup_path/$reponame/log/svnlog.log
path=/var/www/svn/
if ! type -path "$backup_path/$reponame" > /dev/null 2>&1; then mkdir -p "$backup_path/$reponame"; fi
if ! type -path "$backup_path/$reponame/log" > /dev/null 2>&1; then mkdir -p "$backup_path/$reponame/log";cd  "$backup_path/$reponame/log/";touch svnlog.log backuped-revision.txt incremental-revision.txt current-revision.txt; fi
#Backup location...............

#Backuped Revision location
BR=$backup_path/$reponame/log/backuped-revision.txt
in=$backup_path/$reponame/log/incremental-revision.txt
#read BR_var < <(cut -f1 -d "" $BR)
CR=$backup_path/$reponame/log/current-revision.txt
svnlook youngest $path/$reponame > $CR
#`read CR_var < <(cut -f1 -d "" $CR)`
read -a CR_var < $CR
echo "$CR_var CR_var"
#Below should be present.
#if ! type -path "$backup_path/$reponame" > /dev/null 2>&1; then mkdir -p "$backup_path/$reponame"; fi
#if [ $(find $backup_path/$reponame -name full* | wc -l) -eq 0 ] > /dev/null 2>&1; then echo "incr fails,No any full backup fuond"; fi

#start backup from below revision number.
#echo "backup is already done of revision: $BR_var. Now start backup from revision $(expr $BR_var +1)"
expr $CR_var + 1 > $in
read -a REV < $in
echo "++++revision "$REV""

for (( i = 1; i <= 2; i++ ))
do
svnadmin dump $path/$reponame  > $backup_path/$reponame/full_"$DATE"_revision_0:"$CR_var".dump
if test $? -eq 0
then
cat $CR > $BR ###update revision in
echo " Full Backup is successfully Repo($reponame):Revision from revision "0 to $CR_var" Successfull">  $LOG
Subject="Backup Successfully of SVN Repo($reponame)( $i ) :: $DATE"
i=5
else
echo  "Repo $reponame backup not done: Error" >  $LOG
Subject="Error in backup of repo $reponame ( $i ) :: $DATE"
fi
done

cat $LOG  | mail -s "$Subject" $EMail_Addr


done
} < /repolist.txt

Incremental Scripts: schedule  this scripts every day Excluded Saturday

#!/bin/bash
ls -1tr /var/www/svn/ >/repolist.txt
{ while IFS=' ' read reponame
do

DATE=`date "+%d%b%y"`
echo "$reponame"
backup_path=/svnbackup-all
log=$backup_path/$reponame/log/svnlog.log
path=/var/www/svn/
if ! cd "$backup_path/$reponame" > /dev/null 2>&1; then mkdir -p "$backup_path/$reponame"; fi
if ! cd "$backup_path/$reponame/log" > /dev/null 2>&1; then mkdir -p "$backup_path/$reponame/log";cd  "$backup_path/$reponame/log/";touch svnlog.log backuped-revision.txt incremental-revision.txt current-revision.txt;echo 0 > backuped-revision.txt; fi
#Backup location...............

#Backuped Revision location
BR=$backup_path/$reponame/log/backuped-revision.txt
in=$backup_path/$reponame/log/incremental-revision.txt
#read BR_var < <(cut -f1 -d "" $BR)
CR=$backup_path/$reponame/log/current-revision.txt
svnlook youngest $path/$reponame > $CR
echo "*********Repo:: $reponame incrimental backup  status********

1) Backup path:: $backup_path/$reponame" > $log
read -a BR_var < $BR
#echo "$BR_var ......BR_var"
echo "2) BR_var(backedup revision no.it's already done in privious backup ) of Repo ($reponame)::$BR_var" >> $log
#`read CR_var < <(cut -f1 -d "" $CR)`
read -a CR_var < $CR
echo "3) CR_var(Current Revision no.) of Repo ($reponame)::$CR_var " >> $log

#Below should be present.
#if ! type -path "$backup_path/$reponame" > /dev/null 2>&1; then mkdir -p "$backup_path/$reponame"; fi
if [ $(find $backup_path/$reponame -name full* | wc -l) -eq 0 ] > /dev/null 2>&1; then echo "incr may fail. No any full backup fuond"; fi

#start backup from below revision number.
#echo "backup is already done of revision: $BR_var. Now start backup from revision $(expr $BR_var +1)"
#REV1=(expr $BR_var + 1)
#`read REV < <(echo "$(expr $CR_var + 1)")`
expr $BR_var + 1 > $in
read -a REV < $in
echo "4) Scripts is trying to take backup from:: "$REV"" >> $log
#echo "Backup name:: incr_"$DATE"_revision_$REV:"$CR_var".dump" >> $log
for (( i = 1; i <= 2; i++ ))
#while [ $CR_var -ge $REV  ]
do
if  [ $CR_var -eq 0 ]
then
echo "Backup not done 0 revision" >>$log;
cat $CR > $BR ###Basic update
elif [ $BR_var -lt $CR_var ] > /dev/null 2>&1; then
svnadmin dump $path/$reponame -r $REV:$CR_var --incremental > $backup_path/$reponame/incr_"$DATE"_revision_"$REV":"$CR_var".dump
cat $CR > $BR ###update revision in
echo "5) Incrimental Backup is successfully:: Repo($reponame):Revision from revision "$REV to $CR_var" Successfull" >>  $log
echo "6) Backup name:: incr_"$DATE"_revision_$REV:"$CR_var".dump" >> $log
Subject="Backup Successfully of SVN Repo($reponame)( $i ) :: $DATE"
i=5
else
echo  "5) Repo $reponame backup not done type $i time: Error,
it's looks old revision & current revision is same.
but you should check or connect to support@dbindia.com" >> $log
Subject="Backup error of SVN Repo($reponame)( $i ) :: $DATE"

fi
done

cat $log  | mail -s "$Subject" test@example.com
done } < /repolist.txt