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 | # |
---|
14 | import sys |
---|
15 | import os |
---|
16 | import commands |
---|
17 | |
---|
18 | outdir = '/disks/glue1/postgresBackup/dev' |
---|
19 | |
---|
20 | date_string = commands.getoutput ("date +'%y%m%d_%H%M'") |
---|
21 | |
---|
22 | |
---|
23 | outfile = outdir + '/ndg_spatial_' + date_string + '.sql.gz' |
---|
24 | cmd = '/usr/local/pgsql/bin/pg_dump -h glue -U postgres ndg_spatial |gzip -c > %s' %outfile |
---|
25 | print "dumpfile: ", outfile |
---|
26 | print "Executing: ", cmd |
---|
27 | status = os.system (cmd) |
---|
28 | |
---|
29 | outfile = outdir + '/ndg_B_metadata_' + date_string + '.sql.gz' |
---|
30 | cmd = '/usr/local/pgsql/bin/pg_dump -h glue -U postgres ndg_B_metadata | gzip -c > %s' %outfile |
---|
31 | print "dumpfile: ", outfile |
---|
32 | print "Executing: ", cmd |
---|
33 | status = 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 | |
---|
42 | outfile = outdir + '/ndg_fullbackup_' + date_string + '.sql.gz' |
---|
43 | cmd = '/usr/local/pgsql/bin/pg_dumpall -h glue -U postgres | gzip -c > %s' %outfile |
---|
44 | print "dumpfile: ", outfile |
---|
45 | print "Executing: ", cmd |
---|
46 | status = os.system (cmd) |
---|
47 | |
---|
48 | print "postgres_backup script completed " + commands.getoutput ("date +'%y%m%d_%H%M'") |
---|