XMLTagsEditHistoryDiscussion

TODO: We should send e-mails in a better way since this method stopped working when the repository grew.

Sometimes it is useful to send periodic backup emails. For instance, it is useful with public source code. If your computer/server can send emails directly to the Internet, you are all set. Otherwise you might want to use an email account that allows you to send email via SMTP. If you can control the security of your environment, you might want to use a gmail account (not your main gmail account) to provide SMTP access.

This script is the result of our first attempt. You might want to add it to a cron job. We might improve it in the future. Check the "TODO" at the end of this page.

#!/bin/bash

# Backup a SVN repos via email. This script is simple. You could do
# incremental updates, but we are not doing them now. One of the
# reasons is that we are not managing SMTP failures.

DATE_PREFIX=`date +'%Y-%m-%d-%H:%M'`
BASEFILE=/root/BACKUPS/my-svn-repos
FILE=$BASEFILE-$DATE_PREFIX
DESTINATIONS="somebody@example.com"

TARGET=/home/svn/my-src
TARGETBK=$TARGET-backup
TARGETDUMP=$TARGETBK.dump

if [ -e $TARGETBK ] || [ -e $TARGETDUMP ];
  then
    # I guess we should not just RM them.
    echo $TARGETBK or $TARGETDUMP present!
    echo "No backup done : $TARGETBK or $TARGETDUMP present!" \
      | mail -s "Backup problems!" $DESTINATIONS
    exit 1
  fi;

svnadmin hotcopy $TARGET $TARGETBK
svnadmin dump $TARGETBK > $TARGETDUMP

rm -rf $TARGETBK

# You might want to use tar if you don't create new files
# each time you try to make a new backup.

mv $TARGETDUMP $FILE

md5sum $FILE | sed -e 's/\s\s\S*$//' > $BASEFILE.md5.new

if [ ! -f "$BASEFILE.md5" ] || [ "`diff $BASEFILE.md5.new $BASEFILE.md5 | wc -l`" -ne "0" ];
  then
    echo Doing new backups
    bzip2 $FILE &&
    metasend -b -t $DESTINATIONS -s "New Backup Available" -m application/x-tar -f $FILE.bz2 &&
    mv $FILE.bz2 $FILE.bz2.old && cp $BASEFILE.md5.new $BASEFILE.md5
    rm -f $FILE.bz2
  else
    rm -f $FILE
    echo Target has not changed
  fi;

TODO: "metasend" is not sending the file name. What is the simplest way to send a nice message with an attachemnt?

 MIME-Version: 1.0
 To: user@example.com
 Subject: New Backup Available
 Content-ID: 
 Content-type: application/x-tar
 Content-Transfer-Encoding: base64
 From: Backup Robot 
 Message-ID: <4884c91c.2486460a.198c.2baa@mx.google.com>

 QlpoOTFBWSZTWRKiAkEAHnt/3e/YBEB99/////////////4AEAQAAAgAiAAEAMhgHl73fb11
 zu97vvs7fESoV2wQgTblfMdzN73OcpS627ruw5ve8qnR0dAqRIMiLqncZI1oACgAKNdGIoCu
 VOlAQlNTUBGh6gaSbUyjyeimeRppPVPEynoPVAPSNGQ0D1DyjQNMgCSEaIEyTFT9IaT1T9Ta
 o2yp6gbSaGj1NNAaGgNABoGgBkGQ96qACYA
 (the rest of the file)

References

Last update: 2007-12-23 (Rev 13367)

svnwiki $Rev: 12966 $