September 8, 2009
Banged out a quick script for backing up a directory containing a bunch of bzr depots, for use with rsnapshot:
To use:
- Save to /usr/local/bin/backup_bzr.py
- chmod u+x /usr/local/bin/backup_bzr.py
- Edit /etc/rsnapshot.conf and add:
- backup_script /usr/local/bin/backup_bzr.py . [root dir of your bzr dirs] localhost/bzr
Update: Just realized that maybe this isn’t as useful as I thought.
Seeing as how bzr is self-contained, you could probably just rsync the entire directory and get away with it that way. D’oh. So used to old-style VCS that need a separate backup process than ‘cp’.
I’ll leave this code here in case anyone else finds it useful.
Download: backup_bzr.py
- #!/usr/bin/python
- import os
- import subprocess
- import sys
- class App(object):
- def Setup(self):
- # TODO: Proper command line parsing
- if len(sys.argv) < 2:
- print 'Invalid arguments. Specify a destination directory, as well as root directory of bzr depots.'
- return -1
- self.BackupDirectory = sys.argv[1]
- self.RootDirectory = sys.argv[2]
- return 0;
- def IsBzrDirectory(self, p):
- return os.path.exists(os.path.join(p, '.bzr'))
- def RunCommand(self, c):
- print c
- p = subprocess.Popen(c, shell=True)
- if p.wait() != 0:
- raise Exception('Failure running command.')
- def BackupBzrDirectory(self, p):
- backupDirectory = os.path.join(self.BackupDirectory, os.path.split(p)[-1])
- if not os.path.exists(backupDirectory):
- cmd = 'bzr init %s'%(backupDirectory)
- self.RunCommand(cmd)
- pwd = os.getcwd()
- os.chdir(backupDirectory)
- cmd = 'bzr pull %s'%(p)
- self.RunCommand(cmd)
- os.chdir(pwd)
- return 0
- def Run(self):
- e = self.Setup()
- if e != 0:
- return e
- if self.RootDirectory != None:
- for dirName in os.listdir(self.RootDirectory):
- fqp = os.path.join(self.RootDirectory, dirName)
- if self.IsBzrDirectory(fqp):
- e = self.BackupBzrDirectory(fqp)
- if e != 0:
- return e
- return 0
- if '__main__' == __name__:
- sys.exit(App().Run())
No Comments yet »
RSS feed for comments on this post. TrackBack URI
Leave a comment
