source: TI01-discovery/trunk/ingestAutomation/exist_backup.py @ 720

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/TI01-discovery/trunk/ingestAutomation/exist_backup.py@721
Revision 720, 1.6 KB checked in by selatham, 14 years ago (diff)

adding database backup scripts

Line 
1#!/usr/bin/python
2#
3# Usage: exist_backup <database> <target directory>
4#
5# Uses  backup_ndg.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#
15import sys
16import os
17import commands
18
19status = 0
20os.putenv ('PATH', '/usr/local/eXist/bin:/bin:/usr/bin:.')
21os.putenv ('EXIST_HOME', '/usr/local/eXist')
22
23TMP_DIR = '/usr/local/eXist/backup'
24
25if (len(sys.argv) < 3):
26    print "<database> and <target_directory> parameters not supplied - will use defaults"
27    database = 'xmldb:exist://localhost:8080/exist/xmlrpc'
28    target_directory = '/disks/glue1/existBackup/dev/data'
29else:
30    database  = sys.argv[1]
31    target_directory = sys.argv[2]
32
33os.chdir('/usr/local/eXist')
34
35date_string = commands.getoutput ("date +'%y%m%d_%H%M'")
36backup_directory = target_directory + '/eXist_daily_' + date_string
37print " Backup directory: ", backup_directory
38
39cmd = "/usr/local/eXist/bin/backup_ndg.sh -d /usr/local/eXist/backup -u admin -b /db -ouri=" + database
40print "Executing: ", cmd
41status = os.system (cmd)
42if status != 0:
43    sys.exit('FAILED when running the backup command backup_ndg.sh. Status = %s' %status)
44
45cmd = "mkdir " + backup_directory
46print "Executing: ", cmd
47status = os.system (cmd)
48
49cmd = "cp -R " + TMP_DIR + "/* " + backup_directory
50print "Executing: ", cmd
51status = os.system (cmd)
52
53print "eXist_backup script completed " + commands.getoutput ("date +'%y%m%d_%H%M'")
Note: See TracBrowser for help on using the repository browser.