[svn.haxx.se] · SVN Dev · SVN Users · SVN Org · TSVN Dev · TSVN Users · Subclipse Dev · Subclipse Users · this month's index

Re: => Backup ?

From: Rainer Sokoll <R.Sokoll_at_intershop.de>
Date: 2006-09-01 11:20:21 CEST

On Thu, Aug 31, 2006 at 07:30:11PM -0700, Andy Peters wrote:
> On Aug 31, 2006, at 8:25 AM, Anthony Muller wrote:
>
> >Hello,
> >
> >What is the simple way to make a repository backup in order to do a
> >full restore later (if a problem occurred)?
> >
> >Is "hotcopy" the best way?
>
>
> here's a shell script I cooked up.

Here's my solution (with dump, not hotcopy) - it is not perfect:
It reads the repos to dump from a file called "todump", This file
contains the repos in mention line-after line in the form of:
SVNROOT/repo1
SVNROOT/repo2
I have 2 scripts, one for incremental backups, one for full backups. If
the incremental script does not find a full backup, it does a full
backup.

svnbackup.incremental:

------8<----
#!/bin/sh
BACKUPDIR=/svn/backup/incremental/
SVNDIR=/usr/local/subversion-with-ssl-1.3.2/bin/
REPDIR=/svn/svn/
REP=`cat /root/bin/todump`
BZIP2="/usr/bin/bzip2 -9"

for i in ${REP} ; do
  if [ ! -d ${BACKUPDIR}${i} ] ; then
    mkdir -p ${BACKUPDIR}${i}
  fi
  CUR_REV=`${SVNDIR}svnlook youngest ${REPDIR}${i}`
  LAST_FULL_BACKUP=`ls -1 ${BACKUPDIR}../full/${i}/ | sort -n | tail -1`
  # If there is no full backup
  if [ x${LAST_FULL_BACKUP} == x ] ; then
    /root/bin/svnbackup.full ${i}
  else
    # actual version higher than last full backup?
    if [ ${CUR_REV} -gt ${LAST_FULL_BACKUP} ] ; then
      # something changed since the last incremental backup?
      LAST_INCREMENTAL_BACKUP=`ls -1 ${BACKUPDIR}${i}/ | sort -n | tail -1`
      if [ 0${LAST_INCREMENTAL_BACKUP} -ne 0${CUR_REV} ] ; then
        ${SVNDIR}svnadmin dump ${REPDIR}${i} --revision \
          ${LAST_FULL_BACKUP}:${CUR_REV} --incremental | ${BZIP2} > \
          ${BACKUPDIR}$i/${CUR_REV}
      fi
    fi
  fi
done
------8<----

svnbackup.full:
------8<----
#!/bin/sh
TEMPDIR=/svn/temp/full/
BACKUPDIR=/svn/backup/full/
SVNDIR=/usr/local/subversion-with-ssl-1.3.2/bin/
REPDIR=/svn/svn/
REP=`cat /root/bin/todump`
BZIP2="/usr/bin/bzip2 -9"

if [ x${*} != x ] ; then
# we were called with arguments (from svnbackup.incremental)
  if [ ! -d ${BACKUPDIR}${1} ] ; then
    mkdir -p ${BACKUPDIR}${1}
  fi
  CUR_REV=`${SVNDIR}svnlook youngest ${REPDIR}${1}`
  if [ ! -d ${TEMPDIR} ] ; then
    mkdir -p ${TEMPDIR}
  fi
  cd ${BACKUPDIR}
  mv * ${TEMPDIR}
  ${SVNDIR}svnadmin --quiet dump ${REPDIR}${1} | ${BZIP2} > \
    ${BACKUPDIR}${1}/${CUR_REV}
  if [ $? -eq 0 ] ; then
    cd ${TEMPDIR}
    rm -rf *
  else
    cd ${TEMPDIR}
    mv * ${BACKUPDIR}
  fi
else
  for i in ${REP} ; do
    if [ ! -d ${BACKUPDIR}${i} ] ; then
      mkdir -p ${BACKUPDIR}${i}
    fi
    if [ ! -d ${TEMPDIR}${i} ] ; then
      mkdir -p ${TEMPDIR}${i}
    fi
    cd ${BACKUPDIR}
    mv ${i}/* ${TEMPDIR}${i}
    CUR_REV=`${SVNDIR}svnlook youngest ${REPDIR}${i}`
    ${SVNDIR}svnadmin --quiet dump ${REPDIR}${i} | ${BZIP2} > \
      ${BACKUPDIR}${i}/${CUR_REV}
    if [ $? -eq 0 ] ; then
      cd ${TEMPDIR}
      rm -rf *
    else
      cd ${TEMPDIR}
      mv * ${BACKUPDIR}
    fi
  done
fi
------8<----

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@subversion.tigris.org
For additional commands, e-mail: users-help@subversion.tigris.org
Received on Fri Sep 1 11:21:56 2006

This is an archived mail posted to the Subversion Users mailing list.