svnbak.pl: perl Subversion repository backup script

svnbak.pl executing

svnbak.pl executing

What is it?

A Perl cron script that creates and rotates backups of one or more Subversion repositories.

What does it do?

  1. Verifies repositories (svnadmin verify)
  2. Hot copies -or- dumps repositories (uses svnadmin hotcopy -or- svnadmin dump)
  3. Archives all repositories to a single tar file
  4. Gzips tar file
  5. Backup rotation

Other Features

  • Email notifications
  • Nice output
  • Free

Requirements

Operating System: *nixPerl (5.8.5 or higher)Subversiontargzip

Proc::ReliableMIME::LiteMath::Round

Configure

svnbak.pl: Configuration Section

svnbak.pl Configuration Section

At the top of svnbak.pl is a "Configuration Section" that you must add specific information to in order for the script to work.
  • reposDir: full path to your Subversion repository, or the parent directory of all your repositories.
  • destDir: full path to the directory where the backups should be saved. To save backups to a network file system, first mount the file system, then specify the mounted path.
  • maxBaks: maximum number of backups to retain. Once this limit is reached, the script will automatically remove the oldest backup based on it's last modified time.
  • svnBakMethod: type of Subversion backup to create ('hotcopy' or 'dump').
  • tarballName: the name of the backup file. Each backup file will be appended with a 14 digit time stamp to preserve singularity.
  • tmpDir: full path to a new temporary directory to store files before tarballing. This directory should not be an existing directory - it will be deleted!
  • emailPref: when the admin should receive emails ('always', 'errors', 'none').
  • displayTime: display execution time in seconds, per task.

Change Log

0.0.9 - 20141022
  • Syntax error fix.
0.0.8 - 20111130
  • Repos are now tar'd and gzip'd locally in /tmp, and then transferred to the final destination dir.
0.0.7 - 20100209
  • fixed failure of external commands running longer than 60 seconds
0.0.6 - 20091116
  • fixed fatal error when backing up a single repository
  • destination directory is created if it does not already exist
  • changed elapsed time format: 'seconds' -> 's'
0.0.5 - 20090326
  • added backup option of dumping repositories via svnadmin dump
  • increased error checking
  • fixed: some repositories skipped when there was a large number of repositories
0.0.1 - 20090108
  • initial release

Comments

  1. It is working. thanks for the script.
    But i am also looking for a way to backup (scp) to remote server for offside. is there anyway we can add to the script?

    Thanks

  2. @Leap-

    Sure an SCP command could easily be added to this script. If I were you, I'd add it to the "if gzip successful" code block at Line 344 (v0.0.7).

    Since SCP uses SSH, another option would be to mount the remote filesystem using SSHFS (ie: /mnt/remoteserver). Once mounted, just set the "destDir" config option to the directory on the remote server (ie /mnt/remoteserver/path/to/destination/directory).

  3. Lea

    It is working for the scp to remote server. thanks so much.
    But the email is not working. do you have any detail instruction to configure email.

    Thanks again

  4. Leap

    How about incremental backup?
    Thanks

  5. @Leap - incremental backup isn't implemented. Admittedly, that would be a nice feature (I believe "svnadmin dump" even has an incremental flag).

  6. Folley

    Hi,
    Nice script, it's work well manually. But when I configure cron to use it, it doesn't work. The error report says:
    "sh: line 1: svnadmin: command not found".
    I verified if was permissions problem, but, It was.
    Unfortunately I'm still working to resolve this issue, but if you have some ideas to help, I will appreciate.
    Thanks again.

  7. @Folley

    It sounds like the location of the svnadmin binary isn't in the PATH variable for the user you're running the cronjob as. You might try this:

    Login as the cronjob user.

    Type "echo $PATH" to see what directories the user has in the PATH variable.

    Type "whereis svnadmin" to get the location of the svnadmin binary. It will probably return something like "/usr/bin/svnadmin".

    If the directory to svnadmin isn't in your PATH variable, you can permanently add it by editing ~/.bash_profile and adding the directory to the PATH variable.

    The other quick and dirty way to fix this would be to replace all calls to "svnadmin" in the svnbak.pl script with the absolute path to the binary (ie. "/usr/bin/svnadmin").

  8. Folley

    Hi Tim,
    I tried use the PATH, but it's not work, so I put the absolute path and works. Thanks. Later, I will fix this issue in my computer and use with no absolute path.

  9. [...] Also, have a look at svnbak.pl. It takes care of backing up and rotating/archiving... http://www.zulius.com/freebies/perl-...-repositories/ [...]

  10. This is a handy little tool. Thank you. I'm getting a "File size limit exceeded" at the "Gzip-ing tar file..." stage. I believe this is because we are on a 32bit OS. Filesystem is ext3.

  11. Tim of Legond

    We're getting the following error on a RHEL 6 machine;
    syntax error at ./svnbak.pl line 77, near "maxBaks"
    Execution of ./svnbak.pl aborted due to compilation errors.

    We have not modified the macBaks value.

  12. Hi. Sorry about that, I must've made some last minute change that caused a syntax error (lack of a comma on line 75). Version 0.0.9 is now fixed and posted on this page.

Leave a Comment