참고사이트
http://blog.matoski.com/articles/daily-svn-incremental-backup/
-------------------------------------------------------------------------
### 아래 script기능
## 1. 매일 01시에 실행하도록 등록함.
## 2. path_to_repo 아래의 여러 project를 백업함(경로를 통일해야함)
## 3. path_to_dump 아래 매달 1일 새로운폴더를 만들어 전체백업받는 효과
## 4. 매달 1일이후에는 증분백업을 받아서 저장함.
## 5. NAS와 결합하여 스토리지로 백업파일을 복사함.
#!/bin/bash
SCRIPT_NAME=`basename $0`
function help() {
echo
echo "Usage: ${SCRIPT_NAME} <path_to_repo> <path_to_dump>"
echo
echo "Parameters:"
echo " <path_to_repo> - svn repository root dir"
echo " <path_to_dump> - dump root dir"
echo " <compress> - compress the output dump (default: false)"
echo
echo "Examples:"
echo " ${SCRIPT_NAME} /APP/play-2.1.0/yobi/repo/svn/admin /APP/BACKUP"
echo " ${SCRIPT_NAME} /APP/play-2.1.0/yobi/repo/svn/admin /APP/BACKUP true"
echo
exit -1
}
# parameter min 2
if [ ! $# -ge 2 ]; then
help
fi
# parameter setting
PATH_TO_REPO=$1
REPO_ROOT=$1
PATH_TO_DUMP=$2
DUMP_ROOT=$2
COMPRESS=$3
# Check if they are empty and if they are quit
if [[ -z "$PATH_TO_REPO" || -z "$PATH_TO_DUMP" ]]; then
help
fi
if [ "$COMPRESS" == "true" ]; then
COMPRESS="true"
else
COMPRESS="false"
fi
# Check if the repo path exists, and if it's a valid SVN repository
if [ ! -d "$PATH_TO_REPO" ]; then
echo "Directory ${PATH_TO_REPO} doesn't exist."
echo "Exiting."
exit -1
fi
# today YYYYMM ex) 2014-02-24 is 201402
# dir YYYYMM
# file is YYYYMMDDHHMM
tdy_YYYYMM=$(date +"%Y%m")
tdy_YYYYMMDD=$(date +"%Y%m%d%H%M")
# Check if destination exist and if we have writing permissions
# and if it doesn't then create it
if [ ! -d "$DUMP_ROOT/$tdy_YYYYMM" ]; then
echo "Dump directory doesn't exist, creating a new directory: $DUMP_ROOT/$tdy_YYYYMM"
mkdir -p "$DUMP_ROOT/$tdy_YYYYMM"
fi
# Check if the directory has writing permissions
if [ ! -w "$DUMP_ROOT/$tdy_YYYYMM" ]; then
echo "No writing permissions."
echo "Exiting."
exit -1
fi
for dir in $REPO_ROOT/*/
do
dir=${dir%*/}
SVN_PROJECT_NM="${dir##*/}"
echo "start --- $SVN_PROJECT_NM ---"
# Check if SVN folder is valid, check for format file in the directory
if [ ! -f "${REPO_ROOT}/${SVN_PROJECT_NM}/format" ]; then
echo "Probably not a valid SVN repository."
echo "Exiting."
exit -1
else
echo "Probably a valid SVN repository detected. Continuing."
fi
# Get the full paths if we have relative paths in the command line
PATH_TO_REPO=`cd $REPO_ROOT/$SVN_PROJECT_NM; pwd`
PATH_TO_DUMP=`cd $DUMP_ROOT/$tdy_YYYYMM; pwd`
IDENTIFIER_PATH="$PATH_TO_DUMP"
DUMP_FILE_MASK="$IDENTIFIER_PATH"
# Check if the identifier exists
if [ ! -f "$IDENTIFIER_PATH" ]; then
# Doesn't exist, so we create it and set it to revision 0
echo "-1" > "$IDENTIFIER_PATH"
fi
CYGWIN=`uname -o`
# Set up some stuff for cygwin
REPO_URL="file:///$PATH_TO_REPO"
REPO_DIR="$PATH_TO_REPO"
# Get the last revision from the directory repository
REPO_LAST_REVISION=`svn info $REPO_URL | grep "^Revision: " | sed "s/Revision: //g"`
REPO_DUMPED_REVISION=`cat "$PATH_TO_DUMP/$SVN_PROJECT_NM"`
# check if the call succeded
if [[ $REPO_LAST_REVISION != [0-9]* ]]; then
echo "Cannot fetch information from SVN repository"
exit -1
fi
# Increment it by one number from the last revision
# so we don't re dump the last one again
REPO_DUMPED_REVISION=$(($REPO_DUMPED_REVISION+1))
echo "Settings"
echo " Compress: ${COMPRESS}"
echo " Directory: ${REPO_URL}"
echo " Dump: ${PATH_TO_DUMP}"
echo " SVN_PROJECT_NM: ${SVN_PROJECT_NM}"
echo " Cygwin: ${CYGWIN}"
echo
echo "Repository"
echo " Revisions: ${REPO_LAST_REVISION}"
echo " Dumping from: ${REPO_DUMPED_REVISION}"
echo
if [ $REPO_DUMPED_REVISION -gt $REPO_LAST_REVISION ]; then
echo "ERROR: Dumped revision bigger than the revision in the repository"
echo "Exiting."
continue
fi
echo "Starting to dump"
padding_rev=`printf "%08d" $REPO_LAST_REVISION`
padding_srt=`printf "%08d" $REPO_DUMPED_REVISION`
dump_file="$PATH_TO_DUMP/$tdy_YYYYMMDD.$SVN_PROJECT_NM.rev.$padding_srt.$padding_rev.svndump"
echo "dump_file==>$dump_file"
if [ "$COMPRESS" == "true" ]; then
dump_file="${dump_file}.gz"
fi
echo " Dumping revision $REPO_DUMPED_REVISION ~ $REPO_LAST_REVISION"
if [ "$COMPRESS" == "true" ]; then
svnadmin dump "$REPO_DIR" --revision "$REPO_DUMPED_REVISION:$REPO_LAST_REVISION" --incremental --deltas -q | gzip > $dump_file
else
svnadmin dump "$REPO_DIR" --revision "$REPO_DUMPED_REVISION:$REPO_LAST_REVISION" --incremental --deltas -q > $dump_file
fi
# put the new dumped revision in the file
echo $REPO_LAST_REVISION > "$PATH_TO_DUMP/$SVN_PROJECT_NM"
echo "end --- $SVN_PROJECT_NM ---"
done
echo "Done."