-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path#cli.py
31 lines (27 loc) · 892 Bytes
/
#cli.py
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
from argparse import Action, ArgumentParser
class DriverAction(Action):
def __call__(self,parser,namespace,values,option_string=None):
driver,destination = values
namespace.driver = driver.lower()
namespace.destination = destination
def create_parser():
parser=ArgumentParser(description="""
Back up PostgreSQL databases locally or to AWS S3.
""")
parser.add_argument("url", help="URL of database to backup")
parser.add_argument("--driver",
help="how & where to store backup",
nargs=2,
action=DriverAction,
required=True)
return parser
def main():
import boto3
from pgbackup import pgdump,storage
args=create_parser().parse_args()
dump=pgdump.dump(args.url)
if args.driver == 's3':
storage.s3(client,dump.stdout,args.destination,'example.sql')
else:
outfile=open(args.destination,'wb')
storage.local(dump.stdout, outfile)