Ruby script for subversion backups
My subversion backups are automatically created after a commit. I use the post-commit script to do this. In the hooks directory of your repository there is a file called post-commit.templ
that explains how the post-commit script works. Take a look at it for more information about this.
The post-commit
script is called with two arguments, repository
and revision
. These two arguments contains information you may want to use.
My backup script looks like this.
#!/usr/bin/ruby
# post commit script for backing up the source repository
repository = ARGV[0]
revision = ARGV[1]
# create dump file
date = Time.new.strftime("%Y-%m-%d")
filename = "/home/peter/subversion-#{date}-r#{revision}.dump"
system("svnadmin dump /var/lib/svn > #{filename}")
# upload file
remote = "peter@allerhande:/home/peter/backup/subversion"
ssh = "ssh -i /home/peter/.ssh/rsync-key"
system("rsync -e '#{ssh}' #{filename} #{remote}")
It should be obvious that this is one of those script that is called secret software.
To create a backup, I first create a filename with the current date and the revision number. Then I use svnadmin
to create a dumpfile with that filename. Then I use rsync
to upload it to another computer.
More information about rsync can be found in my previous post.
0 Comments:
Post a Comment
<< Home