Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

How i can do SVN Repositories Backup step by step.... i want to backup the Repositories itself .... i don't want to backup it as folder ....

share|improve this question
    
Why not as a dump file? –  Oskar Duveborn Aug 29 '10 at 16:24
    
possible duplicate of Best way to do Subversion backups? –  EEAA Aug 29 '10 at 19:11

4 Answers 4

up vote 9 down vote accepted

step 1 Create a script or batch file that runs the command

svnadmin dump REPOS_PATH > backupfile

svnadmin is a program that comes with svn it will be in the bin folder

backupfile is the file that the repository will get dumped to

REPOS_PATH is the location of the repository

see http://svnbook.red-bean.com/en/1.1/re31.html for more details

step 2. Run the script/batch file to test the backup.

step 3. Test that the backup works by running the command

svnadmin load test_path < backupfile

Now try out the repository created in test_path to make sure it works ok - it should and as a bonus it should work with newer versions of svn.

share|improve this answer
    
please if you know another method becouse it is hard to understand ....and becouse i dont have a wide background about this OS –  Mohammad AL-Rawabdeh Aug 29 '10 at 12:04
    
edited so it cannot be easier to understand HTH –  Adam Butler Aug 29 '10 at 17:45
    
please if you can help me .... when i made the backup in the "root" /home ... the size of the root space not enough so i try to make the backup on other place "/backup" but the following message appear : (-bash: file_name : Prmission denied) –  Mohammad AL-Rawabdeh Aug 30 '10 at 11:02
    
Few questions - commands to find answers in brackets. What operating system (uname -a)? what user is this running as (whoami)? does the /backup folder exist and do you have permissions (ls -l /)? Is this on a disk that is mounted read/write (mount)? –  Adam Butler Aug 30 '10 at 11:22
  1. Stop the server running
  2. Copy the entire directory containing the repo and hooks and config files.
  3. Copy your Apache config too, if you use it and it's not stored in above dir anyway.

that's it.

You can restore on the same machine, or a similar one (eg windows -> windows). if you want to restore from Windows to Linux (say) then you'll want to dump and load the repository instead. You'll still need to copy the rest of the directory as well.

Suggestions to use rsync to copy everything is a good one (but you;ll have to stop the server to always get a good backup), or use svnsync which is an excellent incremental backup utility for SVN. (you'll still have to copy the hooks and config as well though - I rsync those and svnsync the repo)

share|improve this answer
    
Good point - stopping the server helps if the repo is in use. Saving the ssh configs would be a point too. –  Andreas Rehm Aug 29 '10 at 13:49

Following a script that you can save as : svnbackup.sh

    #!/bin/bash

appname=`basename $0`

#
# Set some defaults
#
increment=100
start=""
default_history_file="last_saved"
history_file=""
dumpfilepath="."
dumpfilename="dumpfile"
verbose=false
sshopts=""
identity=""

#
# Function to explain how to use the program
#
function usage () {
    echo
    echo "$appname [-h]"
    echo "$appname [-v] [-i increment] [-s start_rev] [--scp remote] [--identity ssh-key] [--ssh-opts ssh options] [--history-file file] [--out-dir directory name] [--compress (gzip|bzip2)] [--file-name dumpfile-base-name] svn_repository_path"
    cat - <<EOF

This script dumps a subversion repository to a series of compressed
files.  It uses a local file to remember the last changeset dumped so
the script can be used to generate files for backups.

Using the --scp option, the backup files can be generated on one
machine and copied to a backup server once dumped.

  -v             -- Verbose mode
  -i increment   -- How many revisions to include in each dump file.
  --file-name base -- Base name for dump files, defaults to "dumpfile".
  -s start_rev   -- First revision to dump.
  --scp remote   -- Location for remote backups.  Files are transfered via scp,
                    then removed from the local directory.
  --identity     -- Identity file for scp transfer
  --ssh-opts      -- options to use for scp
  --history-file -- path and filename of historyfile to use
  --out-dir      -- path where svn dump files should be written, defaults to "."
  --compress     -- compression method (gzip or bzip2, defaults to bzip2)
EOF
    echo
    echo "Example:"
    echo "  $appname -v -i 100 --scp user@backupserver:/backups/svn /svn/Project"
    echo
    exit $1
}

compress_app="bzip2"
compress_ext="bzip2"

#
# Process arguments
#
while [ $# -gt 0 ]
do
    opt="$1"
    case "$opt" in
        -h) usage 0;;
        -i) increment=$2;
            shift;;
        -s) start=$2;
            shift;;
        --scp) dest="$2"; 
            shift;;
        --identity) identity="$2";
            shift;;
        --ssh-opts)  sshopts="$2";
            shift;;
        --history-file) history_file="$2";
            shift;;
        --out-dir) dumpfilepath="$2";
            shift;;
        --file-name) dumpfilename="$2";
            shift;;
        -v) verbose=true;;
        --compress)
            case "$2" in
                bzip2|bz|bzip) 
                    compress_app="bzip2"; 
                    compress_ext="bzip2";;
                gzip|gz)
                    compress_app="gzip";
                    compress_ext="gz";;
            esac;
            shift;;
        *) break;;
    esac
    shift
done

repository="$1"
if [ -z "$repository" ]
then
    echo "Failed: Repository argument required"
    usage 1
fi

if [ -z "$history_file" ]
then
    history_file="$dumpfilepath/$default_history_file"
fi

if [ "x${start}" = "x" ]
then
    # if [ -s $history_file ]              #Blocco Rinominato per NON Tenere Conto Last_saved
    # then
        # loop_first=`cat $history_file`
    # else
        # loop_first=0
    # fi
     loop_first=0
else
    loop_first=$start
fi
youngest=`svnlook youngest "$repository"`

$verbose && echo "Backing up: $repository"
$verbose && echo "      From: $loop_first"
$verbose && echo "        To: $youngest"
if [ "$dest" != "" ]
then
    $verbose && echo "      Dest: $dest"
fi
if [ "$identity" != "" ] ; then
    $verbose && echo "  Identity: $identity"
fi
if [ "$sshopts" != "" ] ; then
    $verbose && echo "  ssh opts: $sshopts"
fi
$verbose && echo "Hist. file: $history_file"
$verbose && echo "Chunk size: $increment"

#
# Function to do the backup for one set of revisions
#
function backup_revs () {
    typeset first=$1
    typeset last=$2
    typeset repo=$3

    if [ "$first" != "0" ]
    then
        incremental="--incremental"
    fi

    repo_name=`basename "$repo"`
    dumpfile="$dumpfilepath/${dumpfilename}-${repo_name}-${first}-${last}.${compress_ext}"

    $verbose && echo -n "Dumping ${first}:${last} ..."

    svnadmin dump -q "$repo" $incremental --revision ${first}:${last} \
        | "$compress_app" > "$dumpfile"
    RC=$?

    $verbose && echo

    if [ $RC -ne 0 ]
    then
        rm -f "$dumpfile"
        return $RC
    fi

    $verbose && echo "Created $dumpfile"

    if [ "$dest" != "" ]
    then
        if [ -z "$identity" ] ; then
            scp $sshopts "$dumpfile" "$dest"
        else
            scp $sshopts -i $identity "$dumpfile" "$dest"
        fi
        RC=$?
        rm -f "$dumpfile"
    fi

    return $RC
}

#
# Do the incremental dumps
#

if [[ $youngest -eq $loop_first ]]
then
    $verbose && echo "No new changesets to dump"
    exit 0
fi

let loop_last=($loop_first + $increment)

if [[ $loop_first -ne 0 ]]
then
    let loop_first=($loop_first + 1)
fi

while [[ $loop_first -le $youngest ]]
do

    if [ $loop_last -lt $youngest ]
    then
        # A full "increment"
        backup_revs $loop_first $loop_last "$repository" || exit 1
        #echo $loop_last > $history_file
    else
        # In case the last few revs do not make up a full "increment"
        backup_revs $loop_first $youngest "$repository" || exit 1
        #echo $youngest > $history_file
    fi

    let loop_first=($loop_last + 1)
    let loop_last=($loop_last + $increment)
done

exit 0
share|improve this answer

Just create a copy of the svn directory.

Edit:

As already mentioned - you need to stop the svn server first.

You need to stop apache and ssh too, if you use them to access your repo.

share|improve this answer
    
may be you mean the following command :- svnadmin hotcopy path/to/repository path/to/backup --clean-logs ..... if you mean it i read in some referance this method it is not recommended –  Mohammad AL-Rawabdeh Aug 29 '10 at 12:09
    
No - just copy the folder. Your repo reside in a folder. You can just copy or better rsync the folder. –  Andreas Rehm Aug 29 '10 at 12:34
2  
Just copying the directory without stopping all SVN access first is a really bad idea, you might end up with an inconsistent backup. Always use svnadmin hotcopy or completely stop all SVN access as noted in the answer by @gbjbaanb –  rmyates Aug 29 '10 at 16:04
    
That's true - if edited my post to reflect these issues. –  Andreas Rehm Sep 1 '10 at 9:39

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.