-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdb_archive_py
More file actions
executable file
·54 lines (35 loc) · 1.42 KB
/
db_archive_py
File metadata and controls
executable file
·54 lines (35 loc) · 1.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#! /usr/bin/env python
import datetime
import os
import pg
import glob
#delete unsaved aoi from ncgap
ncgap_con = pg.connect(dbname='ncgap', host='localhost', user='postgres')
querystr = 'delete from aoi where username is null'
ncgap_con.query(querystr)
#delete unsaved aoi from swgap
swgap_con = pg.connect(dbname='swgap', host='localhost', user='postgres')
swgap_con.query(querystr)
#delete unsaved aoi from segap
segap_con = pg.connect(dbname='segap', host='localhost', user='postgres')
segap_con.query(querystr)
#delete unsaved aoi from prgap
prgap_con = pg.connect(dbname='prgap', host='localhost', user='postgres')
prgap_con.query(querystr)
date_obj = datetime.datetime.today()
ncgap_file = date_obj.strftime("ncgap_%m_%d_%Y")
swgap_file = date_obj.strftime("swgap_%m_%d_%Y")
segap_file = date_obj.strftime("segap_%m_%d_%Y")
prgap_file = date_obj.strftime("prgap_%m_%d_%Y")
#dump ncgap
ncgap_dump = "su postgres -c '/usr/local/pgsql/bin/pg_dump ncgap > /data/db_archives/%s'" % ncgap_file
os.system(ncgap_dump)
#dump swgap
swgap_dump = "su postgres -c '/usr/local/pgsql/bin/pg_dump swgap > /data/db_archives/%s'" % swgap_file
os.system(swgap_dump)
#dump segap
segap_dump = "su postgres -c '/usr/local/pgsql/bin/pg_dump segap > /data/db_archives/%s'" % segap_file
os.system(segap_dump)
#dump prgap
prgap_dump = "su postgres -c '/usr/local/pgsql/bin/pg_dump prgap > /data/db_archives/%s'" % prgap_file
os.system(prgap_dump)