Merge "armband: adding pod2, and disabling jobs for pod1"
[releng.git] / utils / test / result_collection_api / update / backup.py
1 ##############################################################################
2 # Copyright (c) 2016 ZTE Corporation
3 # feng.xiaowei@zte.com.cn
4 # All rights reserved. This program and the accompanying materials
5 # are made available under the terms of the Apache License, Version 2.0
6 # which accompanies this distribution, and is available at
7 # http://www.apache.org/licenses/LICENSE-2.0
8 ##############################################################################
9 import os
10 import argparse
11 import datetime
12
13 from utils import execute, main, get_abspath
14
15 parser = argparse.ArgumentParser(description='Backup MongoDBs')
16
17 parser.add_argument('-u', '--url',
18                     type=str,
19                     required=False,
20                     default='mongodb://127.0.0.1:27017/',
21                     help='Mongo DB URL for Backups')
22 parser.add_argument('-o', '--output_dir',
23                     type=str,
24                     required=False,
25                     default='./',
26                     help='Output directory for the backup.')
27
28 parser.add_argument('-d', '--db',
29                     type=str,
30                     required=False,
31                     default='test_results_collection',
32                     help='database for the backup.')
33
34
35 def backup(args):
36     db = args.db
37     out = get_abspath(args.output_dir)
38     now = datetime.datetime.now()
39     out = os.path.join(out, '%s__%s' % (db, now.strftime('%Y_%m_%d_%H%M%S')))
40     cmd = ['mongodump', '-o', '%s' % out]
41     execute(cmd, args)
42
43 if __name__ == '__main__':
44     main(backup, parser)