add mongodb backup and restore scripts in testAPI
[releng.git] / utils / test / result_collection_api / update / restore.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 argparse
10
11 from utils import execute, main, get_abspath
12
13 parser = argparse.ArgumentParser(description='Restore MongoDBs')
14
15 parser.add_argument('-u', '--url',
16                     type=str,
17                     required=False,
18                     default='mongodb://127.0.0.1:27017/',
19                     help='Mongo DB URL for Backup')
20 parser.add_argument('-i', '--input_dir',
21                     type=str,
22                     required=False,
23                     default='./',
24                     help='Input directory for the Restore.')
25 parser.add_argument('-d', '--db',
26                     type=str,
27                     required=False,
28                     default=None,
29                     help='database for the restore.')
30
31
32 def restore(args):
33     input_dir = get_abspath(args.input_dir)
34     cmd = ['mongorestore', '%s' % input_dir]
35     execute(cmd, args)
36
37
38 if __name__ == '__main__':
39     main(restore, parser)