2

I have this command that I'm told will do a full backup of Subversion (tell me if that's not true):

svnadmin dump /shared/svnrepos | gzip /shared/backup/snvfull.svn.gz

I'm not a Linux person. I just simply want it to run nightly at 7pm and overwrite the file nightly. It takes quite a while to run though (around 4-5 hours creating around a 28GB file)

Can someone please tell me how to set it up as a cron job in Linux as the root user? (It's Gentoo if that matters)

If it's easier to run a Windows task from the "backup server" just let me know how to create that task to remote in via SSH and run that command as the root user.

Thank you!

P.S. if there's a better/easier way to backup a large SVN, please let me know...I know nothing about Subversion but I'm still stuck dealing with it.

TheCleaner
  • 32,627
  • 26
  • 132
  • 191

2 Answers2

3

Your command will work.

Create a dump script such as svndump.sh

#!/bin/bash
date=`date +%Y-%m-%d`
svnadmin dump /shared/svnrepos | gzip /shared/backup/snvfull_$date.svn.gz

Edit Crontab file crontab -e add

0 19 * * * root /path-to-svn-dump/svndump.sh file 

every day at 7pm this will dump your file

On windows create a bat file such as

for /F "tokens=6,7,8 delims=/ " %%i in ('echo.^|date^|find "current" ') do set today=%%k%%j%%i

set backupdate=%today%
cd "C:\backups\svn"

svnadmin dump "C:\svn_repository\your_repo" > "C:\backups\svn\yourbackup_%backupdate%.svn"

Add this file to scheduled jobs for desired time to run.

PoX
  • 258
  • 2
  • 11
  • This works but I just need it to overwrite the .gz file daily...no need for multiple dates that I can tell. – TheCleaner Aug 14 '12 at 19:26
  • then remove date use same file name that should work for you. – PoX Aug 14 '12 at 19:43
  • BTW, I should note that I had to set the permissions to 755 to get it to run. You probably knew that, but I didn't. – TheCleaner Aug 22 '12 at 13:24
  • I should also add, I was having trouble with it finishing. Apparently after some searching it is a known bug. You have to redirect output such as svndump.sh > /var/log/svndump.log 2>&1 – TheCleaner Aug 30 '12 at 20:05
2

svnadmin dump should work but you can also use svnandmin hotcopy. I use the following script from cron to back up multiple repositories, compress them and keep the last few days:

#!/bin/sh
#
# Backup-svn: Back up each repository under /svn using 'svnadmin hotcopy'.

svn_dir=/my/svn/directory
backup_dir=/my/svn/backup/directory
date_stamp=`date +%Y-%m-%d`
repo_list=`ls -d $svn_dir/*/conf | sed -e "s:^$svn_dir/::" -e 's:/conf$::'`
keep_days=5

renice 5 -p $$ > /dev/null 2>&1
ionice -c 3 -p $$ > /dev/null 2>&1

cd $backup_dir

for repo in $repo_list ; do
        dest=$repo-$date_stamp
    dest_tmp=$backup_dir/$dest

    rm -rf $dest_tmp

    date +"%F %T: Starting hotcopy for $repo"
    svnadmin hotcopy $svn_dir/$repo $dest_tmp

    date +"%F %T: Archiving $repo"
    tar -czf $dest.tar.gz $dest_tmp
    du -sh $dest.tar.gz $dest_tmp

    date +"%F %T: Removing $repo"
    rm -rf $dest_tmp &

    for old_backup in `ls $repo-2*.tar.gz | sort -r | sed "1,${keep_days}d"` ; do
        date +"%F %T: Removing $old_backup"
        rm $old_backup
    done
done
Gerald Combs
  • 6,441
  • 25
  • 35