vcs/svn

Subversion 백업, 복구

C/H 2014. 11. 7. 08:30

백업과 복구

# 백업
svnadmin dump /home/svn/project > project.dump

# 복구
svnadmin load /home/svn/project < project.dump

# 무결성 검사
svnadmin verify /home/svn/project

전체 백업

http://media.pragprog.com/titles/pg_svn/code/full-backup.pl 다운로드후 실행

#!/usr/bin/env perl
#---
# Excerpted from "Pragmatic Guide to Subversion",
# published by The Pragmatic Bookshelf.
# Copyrights apply to this code. It may not be used to create training material, 
# courses, books, articles, and the like. Contact us if you are in doubt.
# We make no guarantees that this code is fit for any purpose. 
# Visit http://www.pragmaticprogrammer.com/titles/pg_svn for more book information.
#---
# 
# Perform a full backup of a Subversion repository. 

$svn_repos = "/home/svn/repos"; 
$backups_dir = "/home/svn/backups"; 

$backup_file = "full-backup." . `date +%Y%m%d%H%M%S`; 
$youngest = `svnlook youngest $svn_repos`; 
chomp $youngest; 

print "Backing up to revision $youngest\n"; 
$svnadmin_cmd = "svnadmin dump --revision 0:$youngest " . 
                "$svn_repos > $backups_dir/$backup_file"; 
`$svnadmin_cmd`; 

print "Compressing dump file...\n"; 
print `gzip -9 $backups_dir/$backup_file`; 

open(LOG, ">$backups_dir/last_backed_up"); 
print LOG $youngest; 
close LOG;

http://www.techrepublic.com/blog/linux-and-open-source/automate-subversion-backups/

#!/bin/sh

date="`date +%Y-%m`"
svnbasedir="/home/svn"
svnfullbkdir="/home/backup/full"
svnincbkdir="/home/backup/incremental"
echo "+++ Backing up subversion repositories..."

for repo in mystuff ; do
    echo ""
    mkdir -p ${svnfullbkdir}/${date}
    /usr/bin/hot-backup.py ${svnbasedir}/${repo} ${svnfullbkdir}/${date}

	if [ "$?" != "0" ]; then
        echo "!! Hot backup failed on repository: ${repo}"
    fi

    lastrev="`svnlook youngest ${svnbasedir}/${repo}`"
    echo "** Creating new baseline for ${repo} (at revision ${lastrev})..."
    mkdir -p ${svnincbkdir}/${repo}.tmp
    svnadmin dump -q ${svnbasedir}/${repo} >${svnincbkdir}/${repo}.tmp/baseline-${lastrev}

    if [ "$?" == "0" ]; then
        rm -f ${svnincbkdir}/${repo}/{baseline,commit}*
        mv -f ${svnincbkdir}/${repo}.tmp/baseline-${lastrev} ${svnincbkdir}/${repo}/
    else
        echo "!! Creating new baseline failed!  Left the old baseline and commits intact!"
    fi

    rm -rf ${svnincbkdir}/${repo}.tmp
done
# 백업 실행
full-backup.pl

증분백업

http://media.pragprog.com/titles/pg_svn/code/daily-backup.pl 다운로드 후 실행

#!/usr/bin/env perl
#---
# Excerpted from "Pragmatic Guide to Subversion",
# published by The Pragmatic Bookshelf.
# Copyrights apply to this code. It may not be used to create training material, 
# courses, books, articles, and the like. Contact us if you are in doubt.
# We make no guarantees that this code is fit for any purpose. 
# Visit http://www.pragmaticprogrammer.com/titles/pg_svn for more book information.
#---
# 
# Perform an incremental backup of a Subversion repository.

$svn_repos = "/home/svn/repos"; 
$backups_dir = "/home/svn/backups"; 
$backup_file = "incremental-backup." . `date +%Y%m%d%H%M%S`; 

open(IN, "$backups_dir/last_backed_up"); 
$previous_youngest = ; 
chomp $previous_youngest; 
close IN; 
$youngest = `svnlook youngest $svn_repos`; 
chomp $youngest; 

if($youngest eq $previous_youngest) { 
  print "No new revisions to back up.\n"; 
  exit 0; 
}
 
# We need to backup from the last backed up revision 
# to the latest (youngest) revision in the repository 
$first_rev = $previous_youngest + 1; 
$last_rev = $youngest; 

print "Backing up revisions $first_rev to $last_rev...\n"; 
$svnadmin_cmd = "svnadmin dump --incremental " . 
                "--revision $first_rev:$last_rev " . 
                "$svn_repos > $backups_dir/$backup_file"; 
`$svnadmin_cmd`;
 
print "Compressing dump file...\n"; 
print `gzip -9 $backups_dir/$backup_file`;
 
open(LOG, ">$backups_dir/last_backed_up"); 
print LOG $last_rev; 
close LOG;
반응형

'vcs > svn' 카테고리의 다른 글

svn commit Subcommand  (0) 2015.11.03
Subversion 프로퍼티  (0) 2014.11.10
CVS 를 Subversion으로 이동 svx2svn  (0) 2014.11.06
Apache Subversion  (0) 2014.11.05
subversion command  (0) 2014.11.04