Portál AbcLinuxu, 30. dubna 2025 16:30
- #!/bin/sh
- #Skript na zalohovani SVN
- #Use: $0 <what to backup>
- #based on http://snippets.dzone.com/posts/show/2635
- call_exit(){
- echo -n "Error code $1 - "
- case "$1" in
- 1)
- echo "Cannot find place for backup, exitting"
- ;;
- 2)
- echo "Backup dir is not present, exitting"
- ;;
- 3)
- echo "Backup dir is not writable, exitting"
- ;;
- esac
- exit $1
- }
- #Setup
- infoDir=${HOME}/.backup #directory, where information about stored revisions is kept
- svnRepository=${HOME}/SVN #repository location
- externalBackupMountPoint1='/mnt/mp3' #first mountpoint to try
- externalBackupMountPoint2='/mnt/local/mp3' #second mountpoint to try
- externalBackupDir='backup' #path in the mounted disc (asume the disc can be mounted on two locations)
- defaultBackup='phd' #what to backup, if nothing is given on commandline
- #End of setup
- #Find a location for the backup
- if [ `mount | grep $externalBackupMountPoint1 | wc -l` -eq 1 ]
- then
- backupDir="$externalBackupMountPoint1/$externalBackupDir"
- elif [ `mount | grep $externalBackupMountPoint2 | wc -l` -eq 1 ]
- then
- backupDir="$externalBackupMountPoint2/$externalBackupDir"
- else
- call_exit 1
- fi
- [ -d $backupDir ] || call_exit 2
- [ -w $backupDir ] || call_exit 3
- echo =============================================
- echo ============ Backup utility =================
- echo =============================================
- echo
- echo Using $backupDir for the backup
- timeStamp=`date +%F-%H-%M-%S`
- #function to dump SVN repository
- dumpDir(){
- dir=$1 #what repository to backup
- dirBaseName=`basename $dir` #basename of the repository to backup
- echo Processing $dir
- youngest=`svnlook youngest $dir` #last (youngest) revision in the repository
- if [ -r $infoDir/$dirBaseName ]; then #if we have information about the last backupped revision
- latest=`cat $infoDir/$dirBaseName` #last revision
- if [ $latest -lt $youngest ]; then #if the last backuped revision is older than the youngest
- cil=${backupDir}/`basename $dir`_$latest_$youngest_$timeStamp.gz #file name where to backup
- echo Running incremental backup from revision $latest to revision $youngest
- echo Target is $cil
- svnadmin dump $dir --incremental -r $latest:$youngest | gzip > $cil # the command itself
- cp $infoDir/$dirBaseName $infoDir/$dirBaseName.old #backup the old setting
- echo $youngest > $infoDir/$dirBaseName #write the information about the backup
- else #no change since the last backup
- echo No need to backup
- fi
- else #if we have no info about last backup, run full backup
- cil=${backupDir}/`basename $dir`_0_$youngest_$timeStamp.gz
- echo Runnig full backup up to revision $youngest
- echo Target is $cil
- svnadmin dump $dir | gzip > $cil #the command itself
- [ -d $infoDir ] || mkdir $infoDir
- echo $youngest > $infoDir/$dirBaseName #write the information about the backup
- fi
- echo Done
- }
- #if nothing is given on commandline, $defaultBackup is backed up
- what=$1
- if [ "x$1" = "x" ]
- then
- what=$defaultBackup
- fi
- case "$what" in
- all)
- for dir in $svnRepository/*
- do
- dumpDir $dir
- done
- ;;
- *)
- dir=${svnRepository}/${what}
- if [ -d $dir ]
- then
- dumpDir $dir
- else
- echo $dir is not a valid SVN repository
- exit 2
- fi
- ;;
- esac
- echo All Done
Tiskni
Sdílej:
what=$1 if [ "x$1" = "x" ] then what=$defaultBackup filze nahradit za
what=${1:-$defaultBackup}P.S.: s/exitting/exiting/g
ISSN 1214-1267, (c) 1999-2007 Stickfish s.r.o.