shell脚本之SVN备份

#!/bin/bash
#############################################################
#       svn backup
# command: svnbackup.sh [dump|hotcopy|rsync|load] [all|other]
# args:
#      dump: backup svn repos
#             all: backup all
#           other: backup the oldversion to newversion
#   hotcopy: reservd
#     rsync: reservd
#      load: load all repos to a new repos
#############################################################

##############################
#  use svnlook to look the 
#  newest version of repos
##############################
LookSvnNewVersion()
{
    v=`svnlook youngest $1`
    return $v
}

##############################
#  write the newest version 
#  to the file which is
#  named .oldsvnversion
##############################
WriteVersionToFile()
{
    echo $1 > $2
}

##############################
#  read the old version 
#  from the file which is
#  named .oldsvnversion
##############################
ReadOldVersionFromFile()
{
    v=`cat $1`
    return $v
}


# the svnpath and the svnversionbackup file path 
svnpath=/home/kehui/AllDisk/UbtHome/svn/project
svnversionfile=/home/kehui/.oldsvnversion
svnbackuppath=/home/kehui/AllDisk/Win7G/svnbackup
date=`date +%y%m%d`
if [ ! -f "$svnversionfile" ];then
    touch $svnversionfile
fi

# read the old version
oldversion=0
ReadOldVersionFromFile $svnversionfile
oldversion=$?

# write the new version
LookSvnNewVersion $svnpath
newversion=$?
WriteVersionToFile $newversion $svnversionfile

# if the args count < 1 , exit
if [ $# -lt 2 ];then
    echo "the args is too short"
    exit
fi

# judge the args
if [ $1 == "dump" ];then
    if [ $2 == "all" ];then
        echo "now begin to dump all repos"
        echo 1| sudo -S svnadmin dump $svnpath > $svnbackuppath/$date-dump
    elif [ $2 == "other" ];then
        if [ $oldversion -lt $newversion ];then
            echo "now begin to dump oldversion-newversion"
            if [ $oldversion -eq 0 ];then
                echo 1 | sudo -S svnadmin dump $svnpath -r $oldversion:$newversion > $svnbackuppath/$date-$oldversion-$newversion.dump
            else
                echo 1 | sudo -S svnadmin dump $svnpath -r $oldversion:$newversion --incremental > $svnbackuppath/$date-$oldversion-$newversion.dump-$date
            fi
        else
            echo "the oldversion >= newversion,donot have to backup"
            exit
        fi
    else
        echo "dump Error args."
    fi
elif [ $1 == "hotcopy" ];then
    echo "hotcopy"
elif [ $1 == "rsync" ];then
    echo "rsync"
elif [ $1 == "load" ];then
    if [ -f $2 ];then
        echo 1 | sudo -S svnadmin create $svnpath-new
        echo 1 | sudo -S svnadmin load $svnpath-new < $2
    else
        echo "the $2 is not exist,exit"
        exit
    fi
else
    echo "Error args."
fi


你可能感兴趣的:(shell脚本之SVN备份)