1 | #!/usr/bin/python |
---|
2 | # |
---|
3 | # Usage: exist_backup <database> <target directory> |
---|
4 | # |
---|
5 | # Uses backup.sh client with the -d dump option to dump the database to disc. |
---|
6 | # The directory tree of dumped files is put in |
---|
7 | # the target directory and is named using the current date and time. |
---|
8 | # |
---|
9 | # On glue this is normally run as user exist |
---|
10 | # |
---|
11 | # History: |
---|
12 | # |
---|
13 | # 27/02/06 SEL First version |
---|
14 | # 10/05/06 SEL Had to add password as one has now been set. |
---|
15 | # Note password is not actually in this public version. |
---|
16 | # Have to change xxxxx to actual in production version. |
---|
17 | # 12/05/06 SEL spelling correction |
---|
18 | # 18/05/06 SEL Don't echo the password |
---|
19 | # 27/09/06 SEL The eXist db has been deployed differently. The database resides in the usual |
---|
20 | # tomcat webapps directory, but the admin client has also been installed at |
---|
21 | # /usr/local/exist-client for doing command-line backups etc. |
---|
22 | # |
---|
23 | import sys |
---|
24 | import os |
---|
25 | import commands |
---|
26 | |
---|
27 | status = 0 |
---|
28 | os.putenv ('PATH', '/usr/local/exist-client/bin:/bin:/usr/bin:.') |
---|
29 | os.putenv ('JAVA_HOME', '/usr/java/jdk1.5.0_03') |
---|
30 | os.putenv ('EXIST_HOME', '/usr/local/exist-client') |
---|
31 | |
---|
32 | #TMP_DIR = '/usr/local/exist/backup' |
---|
33 | |
---|
34 | # replace glue.badc.rl.ac.uk with actual location if different eg. machine.ac.uk or localhost |
---|
35 | if (len(sys.argv) < 3): |
---|
36 | print "<database> and <target_directory> parameters not supplied - will use defaults" |
---|
37 | database = 'xmldb:exist://glue.badc.rl.ac.uk:8080/exist/xmlrpc' |
---|
38 | target_directory = '/disks/glue1/existBackup/dev/data' |
---|
39 | else: |
---|
40 | database = sys.argv[1] |
---|
41 | target_directory = sys.argv[2] |
---|
42 | |
---|
43 | os.chdir('/usr/local/exist-client') |
---|
44 | |
---|
45 | date_string = commands.getoutput ("date +'%y%m%d_%H%M'") |
---|
46 | backup_directory = target_directory + '/eXist_daily_' + date_string |
---|
47 | print " Backup directory: ", backup_directory |
---|
48 | |
---|
49 | cmd = "/usr/local/exist-client/bin/backup.sh -d " + backup_directory + " -u admin -p xxxxxxx -b /db -ouri=" + database |
---|
50 | print "Executing: the actual backup command" |
---|
51 | status = os.system (cmd) |
---|
52 | if status != 0: |
---|
53 | sys.exit('FAILED when running the backup command backup.sh. Status = %s' %status) |
---|
54 | |
---|
55 | #cmd = "mkdir " + backup_directory |
---|
56 | #print "Executing: ", cmd |
---|
57 | #status = os.system (cmd) |
---|
58 | |
---|
59 | #cmd = "cp -R " + TMP_DIR + "/* " + backup_directory |
---|
60 | #print "Executing: ", cmd |
---|
61 | #status = os.system (cmd) |
---|
62 | |
---|
63 | print "eXist_backup script completed " + commands.getoutput ("date +'%y%m%d_%H%M'") |
---|