root@server:~# whereis svnadmin | |
svnadmin: /usr/bin/svnadmin | |
root@server:~# | |
As next we create a empty shell script called: multidump.sh | |
root@server:~# touch multidump.sh | |
Now we make this file executable. | |
root@server:~# chmod +x multidump.sh | |
The content of file | |
#!/bin/bash | |
REPO_BASE=/location/where/your/svn/root/folder/is/ | |
TARGET=/location/of/storage/ | |
SVNADMIN=/usr/bin/svnadmin | |
cd "$REPO_BASE" | |
for f in *; do | |
FILE="$TARGET$f.dump" | |
echo "Dump: $f => $FILE" | |
test -d "$f" && $SVNADMIN dump "$f" > "$FILE" | |
done | |
@echo off | |
rem Where you'd like to store the backups. | |
set path_backup="D:\Backups\SVN" | |
rem Where the working copy is held - whether it has been committed or not. | |
set path_working_copy="C:\Program Files\Apache Group\Apache2\htdocs\myproject" | |
rem Example: C:/svn/data/repositories/reponamehere | |
set path_to_repository="C:\svn\data\repositories\myrepo" | |
rem Usually the name of the repository | |
set dump_name=myrepo | |
rem Example: 2012_06_25__15_34_35__12 | |
set folder_name_backup=%date:~10,4%_%date:~4,2%_%date:~7,2%__%time:~0,2%_%time:~3,2%_%time:~6,2%__%time:~9,2% | |
set path_backup=%path_backup%\%folder_name_backup% | |
set path_backup_hotcopy=%path_backup%\Hotcopy\ | |
set path_backup_working_copy="%path_backup%\Working Copy\" | |
set path_backup_dump=%path_backup%\Dump\ | |
set steps=4 | |
echo Repository Backup Script for SVN by Matt Refghi | |
echo mattrefghi.com/blog/subversion-repository-backup-script/ | |
echo. | |
echo [Step 1 of %steps%] Creating backup folders... | |
mkdir %path_backup% | |
mkdir %path_backup_hotcopy% | |
mkdir %path_backup_working_copy% | |
mkdir %path_backup_dump% | |
echo [Step 1 of %steps%] Backup folders created. | |
echo [Step 2 of %steps%] Starting hotcopy... | |
svnadmin hotcopy %path_to_repository% %path_backup_hotcopy% --clean-logs | |
echo [Step 2 of %steps%] Hotcopy complete. | |
echo [Step 3 of %steps%] Creating dump file... | |
svnadmin dump %path_to_repository% | "%ProgramFiles%\7-Zip\7z.exe" a %path_backup_dump%\%dump_name%.7z -si%dump_name%.svn | |
echo [Step 3 of %steps%] Dump file created. | |
echo [Step 4 of %steps%] Creating copy of working directory... | |
xcopy.exe /s /e /y /i %path_working_copy% %path_backup_working_copy% | |
echo [Step 4 of %steps%] Working directory copied. | |
echo. | |
echo SVN backup complete. | |
pause |
Download the script below | |
Make the script execuatable: chmod +x svn-backup.php | |
Set the 4 configuration variables at the top: $source_dir, $dest_dir, $tmp_dir & $hashfile | |
Run the script: ./svn-backup.php | |
!/usr/bin/php5 -q | |
<?php | |
// Requires PHP5 or the file_put_contents() function from PEAR::Compat | |
$source_dir = "/usr/local/svn"; // this is a directory with my svn repositories in it | |
$dest_dir = "/mnt/backup/svn"; // this is where the svn dumps will go | |
$tmp_dir = "/usr/local/tmp"; // temp dir | |
$hashfile = "/mnt/backup/svn/hashes.txt"; // we only back up repositories which have changed | |
// read in the existing hash file if there is one | |
$hashes = array(); | |
$hashlines = array(); | |
if (file_exists($hashfile)) { | |
$hashlines = file($hashfile); | |
} | |
// build this into a useful array | |
foreach($hashlines as $hashline) { | |
$key = substr($hashline,0,strpos($hashline,":")); | |
$value = substr($hashline,strpos($hashline,":")+1); | |
if ($key && $value) { | |
$hashes[$key] = $value; | |
} | |
} | |
// loop thorugh the repositories in the source directory | |
if ($handle = opendir($source_dir)) { | |
while (false !== ($file = readdir($handle))) { | |
if (is_dir($source_dir."/".$file) && $file != "." && $file != "..") { | |
// generate an md5 hash for the contents of the repository | |
$command = "svnlook info '$source_dir/$file'"; | |
// echo $command."\n"; | |
exec($command,$output); | |
$md5 = trim(md5(trim(str_replace("\n","-",implode("\n",$output))))); | |
if (!isset($hashes[$file]) || $hashes[$file] !== $md5) { | |
// echo "dumping $file\n"; | |
$return = system("mkdir -p $tmp_dir/svn_backup/$file"); | |
$return = system("svnadmin hotcopy $source_dir/$file $tmp_dir/svn_backup/$file"); | |
$return = system("svnadmin dump -q $tmp_dir/svn_backup/$file | bzip2 -c > $dest_dir/$file.bz2"); | |
$return = system("rm -Rf $tmp_dir/svn_backup/$file"); | |
$hashes[$file] = $md5; | |
} | |
} | |
} | |
closedir($handle); | |
} | |
$hashelines = ""; | |
foreach($hashes as $key => $md5) { | |
$hashelines .= "$key:$md5\n"; | |
} | |
file_put_contents($hashfile,$hashelines); |
I’m a DevOps/SRE/DevSecOps/Cloud Expert passionate about sharing knowledge and experiences. I am working at Cotocus. I blog tech insights at DevOps School, travel stories at Holiday Landmark, stock market tips at Stocks Mantra, health and fitness guidance at My Medic Plus, product reviews at I reviewed , and SEO strategies at Wizbrand.
Please find my social handles as below;
Rajesh Kumar Personal Website
Rajesh Kumar at YOUTUBE
Rajesh Kumar at INSTAGRAM
Rajesh Kumar at X
Rajesh Kumar at FACEBOOK
Rajesh Kumar at LINKEDIN
Rajesh Kumar at PINTEREST
Rajesh Kumar at QUORA
Rajesh Kumar at WIZBRAND