Archive

Archive for the ‘scripts’ Category

Script to Backup SVN Repository

February 23, 2012 1 comment

This is a script to backup my svn repositories:

 

#!/bin/bash
# On this script I'm assuming that in the backup path 
# we only have .gz files so I use the same direcotry 
# as temp folder to dump the files there and gzip 
# them later


# Configuration
LOCKFILE=/var/lock/bkp_svn
#repository's names blank space separated
REPO_NAME_LIST="one two website source code"
REPO_PATH="/home/svn/repositories"
BKP_PATH="/backups/svn"
FLAG=0


# Check that there are no running backups
if [ -f $LOCKFILE ]; then
	echo "Instance already running"
	exit 1
fi

# Create the lock file to prevent multiple runs
touch $LOCKFILE

if [ ! -d ${REPO_PATH}/${REPO_NAME} ]; then
	echo "Repository Path: ${REPO_PATH} not found."
	exit 1
fi

# First lets create the dump files
for REPO_NAME in ${REPO_NAME_LIST}
do
	echo "Checking repository: ${REPO_NAME} ..."
	if [ -d ${REPO_PATH}/${REPO_NAME} ]; then
		svnadmin dump -q ${REPO_PATH}/${REPO_NAME} > ${BKP_PATH}/${REPO_NAME}.dump
		echo "${REPO_NAME} dumped."
		FLAG=1
	else
		echo "Repository ${REPO_NAME} not found."
	fi
done

#Now lets create the tar file
if [ ${FLAG} -eq 1 ]; then
	PREFIX_FILENAME=`date +"%y-%m-%d_%H%M"`
	cd ${BKP_PATH}
	tar -zcf ${PREFIX_FILENAME}.tar.gz *dump
	rm *dump
fi

echo "Script Finished"
rm ${LOCKFILE}
exit 0
Advertisements
Categories: backup, scripts, subversion