2222MAX_RETRY = 6
2323LOCAL_REGION = "local"
2424LOG_LEVEL = "INFO"
25- DUMP_PATH = "dump"
25+ DATA_DUMP = "dump"
2626RESTORE_WRITE_CAPACITY = 25
2727THREAD_START_DELAY = 1 # seconds
2828CURRENT_WORKING_DIR = os .getcwd ()
@@ -61,9 +61,9 @@ def get_table_name_matches(conn, table_name_wildcard, separator):
6161def get_restore_table_matches (table_name_wildcard , separator ):
6262 matching_tables = []
6363 try :
64- dir_list = os .listdir ("./" + DUMP_PATH )
64+ dir_list = os .listdir ("./" + args . dumpPath )
6565 except OSError :
66- logging .info ("Cannot find \" ./%s\" , Now trying current working directory.." % DUMP_PATH )
66+ logging .info ("Cannot find \" ./%s\" , Now trying current working directory.." % args . dumpPath )
6767 dump_data_path = CURRENT_WORKING_DIR
6868 try :
6969 dir_list = os .listdir (dump_data_path )
@@ -249,13 +249,13 @@ def do_backup(conn, table_name, read_capacity):
249249 logging .info ("Starting backup for " + table_name + ".." )
250250
251251 # trash data, re-create subdir
252- if os .path .exists (DUMP_PATH + "/" + table_name ):
253- shutil .rmtree (DUMP_PATH + "/" + table_name )
254- mkdir_p (DUMP_PATH + "/" + table_name )
252+ if os .path .exists (args . dumpPath + "/" + table_name ):
253+ shutil .rmtree (args . dumpPath + "/" + table_name )
254+ mkdir_p (args . dumpPath + "/" + table_name )
255255
256256 # get table schema
257257 logging .info ("Dumping table schema for " + table_name )
258- f = open (DUMP_PATH + "/" + table_name + "/" + SCHEMA_FILE , "w+" )
258+ f = open (args . dumpPath + "/" + table_name + "/" + SCHEMA_FILE , "w+" )
259259 table_desc = conn .describe_table (table_name )
260260 f .write (json .dumps (table_desc , indent = JSON_INDENT ))
261261 f .close ()
@@ -270,15 +270,15 @@ def do_backup(conn, table_name, read_capacity):
270270
271271 # get table data
272272 logging .info ("Dumping table items for " + table_name )
273- mkdir_p (DUMP_PATH + "/" + table_name + "/" + DATA_DIR )
273+ mkdir_p (args . dumpPath + "/" + table_name + "/" + DATA_DIR )
274274
275275 i = 1
276276 last_evaluated_key = None
277277
278278 while True :
279279 scanned_table = conn .scan (table_name , exclusive_start_key = last_evaluated_key )
280280
281- f = open (DUMP_PATH + "/" + table_name + "/" + DATA_DIR + "/" + str (i ).zfill (4 ) + ".json" , "w+" )
281+ f = open (args . dumpPath + "/" + table_name + "/" + DATA_DIR + "/" + str (i ).zfill (4 ) + ".json" , "w+" )
282282 f .write (json .dumps (scanned_table , indent = JSON_INDENT ))
283283 f .close ()
284284
@@ -302,10 +302,10 @@ def do_restore(conn, sleep_interval, source_table, destination_table, write_capa
302302
303303 # create table using schema
304304 # restore source_table from dump directory if it exists else try current working directory
305- if os .path .exists ("%s/%s" % (DUMP_PATH , source_table )):
306- dump_data_path = DUMP_PATH
305+ if os .path .exists ("%s/%s" % (args . dumpPath , source_table )):
306+ dump_data_path = args . dumpPath
307307 else :
308- logging .info ("Cannot find \" ./%s/%s\" , Now trying current working directory.." % (DUMP_PATH , source_table ))
308+ logging .info ("Cannot find \" ./%s/%s\" , Now trying current working directory.." % (args . dumpPath , source_table ))
309309 if os .path .exists ("%s/%s" % (CURRENT_WORKING_DIR , source_table )):
310310 dump_data_path = CURRENT_WORKING_DIR
311311 else :
@@ -458,6 +458,7 @@ def do_restore(conn, sleep_interval, source_table, destination_table, write_capa
458458 help = "Restore data only. Do not delete/recreate schema [optional for restore]" )
459459parser .add_argument ("--skipThroughputUpdate" , action = "store_true" , default = False ,
460460 help = "Skip updating throughput values across tables [optional]" )
461+ parser .add_argument ("--dumpPath" , help = "Directory to place and search for DynamoDB table backups (defaults to use '" + str (DATA_DUMP ) + "') [optional]" , default = str (DATA_DUMP ))
461462parser .add_argument ("--log" , help = "Logging level - DEBUG|INFO|WARNING|ERROR|CRITICAL [optional]" )
462463args = parser .parse_args ()
463464
@@ -542,7 +543,7 @@ def do_restore(conn, sleep_interval, source_table, destination_table, write_capa
542543
543544 matching_restore_tables = get_restore_table_matches (args .srcTable , prefix_separator )
544545 logging .info (
545- "Found " + str (len (matching_restore_tables )) + " table(s) in " + DUMP_PATH + " to restore: " + ", " .join (
546+ "Found " + str (len (matching_restore_tables )) + " table(s) in " + args . dumpPath + " to restore: " + ", " .join (
546547 matching_restore_tables ))
547548
548549 threads = []
0 commit comments