source: TI01-discovery/branches/ingestAutomation-upgrade/backup_postgres.py @ 720

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

adding database backup scripts

Line 
1#
2# Make backups of postgres databases on glue
3#
4# Uses  pg_dump and pg_dumpall to get complete dumps to disc.
5# The dump files are named  using the current date and time and
6# are placed in a directory which gets backed up to tape.
7#
8# On glue this is normally run as user postgres
9#
10# History:
11#
12#     1-Mar-2006 SEL First version
13#
14import sys
15import os
16import commands
17
18outdir = '/disks/glue1/postgresBackup/dev'
19 
20date_string = commands.getoutput ("date +'%y%m%d_%H%M'")
21
22
23outfile = outdir + '/ndg_spatial_' + date_string  + '.sql.gz'
24cmd     = '/usr/local/pgsql/bin/pg_dump -h glue -U postgres ndg_spatial |gzip -c > %s' %outfile
25print "dumpfile: ", outfile
26print "Executing: ", cmd
27status = os.system (cmd)
28
29outfile = outdir + '/ndg_B_metadata_' + date_string  + '.sql.gz'
30cmd     = '/usr/local/pgsql/bin/pg_dump -h glue -U postgres ndg_B_metadata | gzip -c > %s' %outfile
31print "dumpfile: ", outfile
32print "Executing: ", cmd
33status = os.system (cmd)
34
35# This version doesn't seem to have the globals only option. do a dumpall instead.
36#outfile = outdir + '/ndg_globals' + date_string  + '.sql.gz'
37#cmd     = '/usr/local/pgsql/bin/pg_dump -h glue -U postgres --globals-only | gzip -c > %s' %outfile
38#print "dumpfile: ", outfile
39#print "Executing: ", cmd
40#status = os.system (cmd)
41
42outfile = outdir + '/ndg_fullbackup_' + date_string  + '.sql.gz'
43cmd     = '/usr/local/pgsql/bin/pg_dumpall -h glue -U postgres  | gzip -c > %s' %outfile
44print "dumpfile: ", outfile
45print "Executing: ", cmd
46status = os.system (cmd)
47
48print "postgres_backup script completed " + commands.getoutput ("date +'%y%m%d_%H%M'")
Note: See TracBrowser for help on using the repository browser.