4

the first part of question how i can make Incremental Backups of SVN Repository ? what is the command do this ....... and how i can do this automatically (OS + UNIX)

2
  • Where do you want to backup to? Another server? Tape?
    – dunxd
    Oct 26, 2010 at 12:59
  • some svn on the same server and other on another server Oct 26, 2010 at 13:03

3 Answers 3

11

If you want to do it yourself, look into the "svnlook youngest" and "svnadmin dump --incremental -r${STARTREV}:${ENDREV}" commands.

I have pasted below the scripts that I use to make full and incremental dumps of my SVN repositories, they store the revision and date of the last backup in subdirectories of /home/svn/var. Make a full dump first, then as many incremental dumps as you want.

Full SVN dump script:

#!/bin/sh

# Full dump of all subversion repositories

# make sure to get the subversion environment variables
. /etc/profile.d/subversion.sh

# path to subversion binaries
SVN_BINPATH=${SVN_HOME}/bin

# path to parent of all repositories to be dumped
SVN_REPPATH=/opt/svn/repositories

# destination directory for backup files
DUMP_DIR=/backup/svn

# status directory
SVN_VAR=/home/svn/var

DATETIME=`date +%Y%m%d`

for rep in ${SVN_REPPATH}/*;
do
  TSTAMP=`date +%s`
  CURR_REV=`${SVN_BINPATH}/svnlook youngest ${rep}`
  REP_BASE=`basename $rep`

  echo "**********************************************************"
  echo "`date --rfc-2822`  - Full back up - ${rep} : "
  echo "     current revision ${CURR_REV}"
  echo

  DUMPFILE=${DUMP_DIR}/${REP_BASE}-${DATETIME}.dmp
  ${SVN_BINPATH}/svnadmin --quiet dump $rep > ${DUMPFILE}
  echo ${TSTAMP} > ${SVN_VAR}/status/dates/${REP_BASE}.dt
  echo ${CURR_REV} > ${SVN_VAR}/status/revisions/${REP_BASE}.rev
  bzip2 --compress --best ${DUMPFILE}
done

echo
echo `ls -hl ${DUMP_DIR}/*.bz2`

Incremental SVN dump script:

#!/bin/sh

# Incremental dump of all subversion repositories

# make sure to get the subversion environment variables
. /etc/profile.d/subversion.sh

# path to subversion binaries
SVN_BINPATH=${SVN_HOME}/bin

# path to parent of all repositories to be dumped
SVN_REPPATH=/opt/svn/repositories

# destination directory for backup files
DUMP_DIR=/backup/svn

# status directory
SVN_VAR=/home/svn/var

DATETIME=`date +%Y%m%d`

for rep in ${SVN_REPPATH}/*;
do
  TSTAMP=`date +%s`
  CURR_REV=`${SVN_BINPATH}/svnlook youngest ${rep}`
  REP_BASE=`basename $rep`

  if [ -e ${SVN_VAR}/status/dates/${REP_BASE}.dt ] ; then
    REP_LAST_BK_TSTAMP=`cat ${SVN_VAR}/status/dates/${REP_BASE}.dt`
    REP_LAST_BK_REV=`cat ${SVN_VAR}/status/revisions/${REP_BASE}.rev`
  else
    REP_LAST_BK_TSTAMP=0
    REP_LAST_BK_REV=0
  fi

  if [ ${CURR_REV} -gt ${REP_LAST_BK_REV} ] ; then
    echo "**********************************************************"
    echo "`date --rfc-2822`  - Incremental back up ${rep} : "
    echo "     oldest revision ${REP_LAST_BK_REV} - newest revision ${CURR_REV}"
    echo

    DUMPFILE=${DUMP_DIR}/${REP_BASE}-${DATETIME}-${REP_LAST_BK_REV}-${CURR_REV}.dmp
    ${SVN_BINPATH}/svnadmin --quiet dump $rep --incremental -r${REP_LAST_BK_REV}:${CURR_REV}> ${DUMPFILE}
    echo ${TSTAMP} > ${SVN_VAR}/status/dates/${REP_BASE}.dt
    echo ${CURR_REV} > ${SVN_VAR}/status/revisions/${REP_BASE}.rev
    bzip2 --compress --best ${DUMPFILE}
  fi
done

echo
echo `ls -hl ${DUMP_DIR}/*.bz2`

Hope this helps.

2
  • I have defined the path to the Subversion installation $SVN_HOME in the /etc/profile.d/subversion.sh file: by importing this file I keep this definition in a single place only and I do not have to repeat it in the backup scripts. Oct 27, 2010 at 21:02
  • Any ideas on how to fix the issue raised by @roffez below? i.e. how the revision numbers overlap by 1 causing restoration issues?
    – Golfman
    Aug 19, 2021 at 19:24
1

Can't comment on the above due to reputation, but the script shown has a bug: the last revision in each incremental backup is also dumped as first revision in the next one, i.e. they overlap by one: For example,

repository-20171115-1-3.dmp   # initial dump, contains rev. 1-3
repository-20171116-3-8.dmp   # second dump, contains 3-8 (should be 4-8!)
repository-20171116-8-15.dmp  # third dump, contains 8-15 (should be 9-15!)

This leads to strange problems when the dumps are loaded back to a repo using "svn load" command - it tries to load the same revision twice (goes mostly undetected but fails if files have been added or deleted, because svn tries then to perform the action again). You can still load these dumps but you need to explicitly state the revision range to omit the first revision in each incremental dump.

1

Please find updated version, which solve the bug of overlap versioning.

#!/bin/sh

# Incremental dump of all subversion repositories

# make sure to get the subversion environment variables
. /etc/profile.d/subversion.sh

# path to subversion binaries
SVN_BINPATH=${SVN_HOME}/bin

# path to parent of all repositories to be dumped
SVN_REPPATH=/opt/svn/repositories

# destination directory for backup files
DUMP_DIR=/backup/svn

# status directory
SVN_VAR=/home/svn/var

DATETIME=`date +%Y%m%d`

for rep in ${SVN_REPPATH}/*;
do
  TSTAMP=`date +%s`
  CURR_REV=`${SVN_BINPATH}/svnlook youngest ${rep}`
  REP_BASE=`basename $rep`

  if [ -e ${SVN_VAR}/status/dates/${REP_BASE}.dt ] ; then
    REP_LAST_BK_TSTAMP=`cat ${SVN_VAR}/status/dates/${REP_BASE}.dt`
    REP_LAST_BK_REV=`cat ${SVN_VAR}/status/revisions/${REP_BASE}.rev`
  else
    REP_LAST_BK_TSTAMP=0
    REP_LAST_BK_REV=0
  fi

  if [ ${CURR_REV} -gt ${REP_LAST_BK_REV} ] ; then
    echo "**********************************************************"
    echo "`date --rfc-2822`  - Incremental back up ${rep} : "
    echo "     oldest revision ${REP_LAST_BK_REV} - newest revision ${CURR_REV}"
    echo
REP_LAST_BK_REV_1=$((REP_LAST_BK_REV+1))
    DUMPFILE=${DUMP_DIR}/${REP_BASE}-${DATETIME}-${REP_LAST_BK_REV_1}-${CURR_REV}.dmp
    ${SVN_BINPATH}/svnadmin --quiet dump $rep --incremental -r${REP_LAST_BK_REV_1}:${CURR_REV}> ${DUMPFILE}
    echo ${TSTAMP} > ${SVN_VAR}/status/dates/${REP_BASE}.dt
    echo ${CURR_REV} > ${SVN_VAR}/status/revisions/${REP_BASE}.rev
    bzip2 --compress --best ${DUMPFILE}
  fi
done

echo
echo `ls -hl ${DUMP_DIR}/*.bz2`

````````````````````````````````````````````

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .