RSS feed icon BTB Shadow Man BiteTheBullet.co.uk logo
Average Rating: 
Empty StarEmpty StarEmpty StarEmpty StarEmpty Star

Total number of ratings: 16

Backing up a Subversion Repository to an FTP Server

I’ve recently added all my modules and projects in to Subversion for version control. Before this I was walking around with them on a USB stick, but I’m working on more complex projects I wanted to get them into a central repository for safe keeping.

This lead me to think about remote backing up of the repository to a FTP server since my ISP gives me 500Mb of space which I never use. Using nothing more than a batch file and some free utilities I’m backing up the SVN repository every night.

Backup Steps in Detail

I wanted to achieve the following steps with my backup

1.    Safely copy the repository without corrupting it
2.    Make the backup file as small as possible
3.    Encrypt the backup file to stop unauthorised access
4.    FTP the backup file to a remote server.
5.    Repeat nightly

I’m going to dump a copy of the repository to c:\backupsvn\<resp_name> , compress and encrypt the dump using 7Zip, FTP the compressed file to a FTP server and finally remove the backup files created during this process.

Requirements and Assumptions

To get started you’ll need to have Filezilla and 7Zip installed on the SVN server.
I’m going to assume that these programs are installed in the default location. Secondly I’m going to assume that the subversion files (binaries) are also in the default location. If any of these are not then simply update the set path statement in the batch file to point to your install locations.

On the SVN server I’m using we have all the repositories inside of the folder c:\svn, i.e. each folder c:\svn\project1, c:\svn\project2 are separate repositories and the backup script will backup the repository you specific in the command line argument.

Again you can correct this by editing the batch file as required if your SVN repositories are not in the c:\svn root folder.

In Use

To use the batch file you should call it with the following parameters

backup.bat <resposity_name> <ftp_username> <ftp_password> <ftp_host_including_path> <encrypting_password>

Then to complete the process just schedule the batch file to be executed everyday at a given time using the Windows Task Scheduler.

 

@echo off

if "%1"=="" goto err

::Usage- backup.bat <repository_FolderName> <ftp_username> <ftp_password> <ftphost_including_path> <password_7zip>

set path=c:\progra~1\7-zip;c:\progra~1\subversion\bin;c:\progra~1\filezilla;c:\winnt\system32


::do a hotcopy of svn repo
svnadmin hotcopy c:\svn\%1 c:\backupsvn\%1

::7zip and encrypt
7z a -r -p%5 c:\backupsvn\%1_backup.7z c:\backupsvn\%1

::ftp to remote server
filezilla %2:%3@%4 -u "c:\backupsvn\%1_backup.7z" ftp://%2:%3@%4 -close -overwrite

::clean up
del c:\backupsvn\%1_backup.7z
rd c:\backupsvn\%1 /q /s

goto end

:err
echo usage: %0 -repository_FolderName -ftp_username -ftp_password -ftphost_including_path -password_7zip
goto end
:end

Download batch file

Privacy PolicyTerms and ConditionsCopyright © 2005 - 2010 BiteTheBullet.co.uk