Skip to content

Commit f3ef8a5

Browse files
committed
support blank prefix separator and use case instead
Used when tables are prefixed without a separtor e.g. testTableOne testTableTwo can be backed up with: ./dynamodump.py -m 'backup' -r 'ap-southeast-2' --prefixSeparator '' -s 'test*' and restored with: ./dynamodump.py -m ‘backup’ -r 'ap-southeast-2' --prefixSeparator '' -s 'test*' -d 'prod*' Resulting restored tables would be: prodTableOne prodTableTwo
1 parent af80634 commit f3ef8a5

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

dynamodump.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/usr/bin/env python
2-
import boto.dynamodb2.layer1, json, sys, time, shutil, os, argparse, logging, datetime, threading
2+
import boto.dynamodb2.layer1, json, sys, time, shutil, os, argparse, logging, datetime, threading, re
33
from boto.dynamodb2.layer1 import DynamoDBConnection
44

55
JSON_INDENT = 2
@@ -37,6 +37,9 @@ def get_table_name_matches(conn, table_name_wildcard, separator):
3737
elif separator == None:
3838
if table_name.startswith(table_name_wildcard.split("*", 1)[0]):
3939
matching_tables.append(table_name)
40+
elif separator == '':
41+
if table_name.startswith(re.sub( r"([A-Z])", r" \1", table_name_wildcard.split("*", 1)[0]).split()[0] ):
42+
matching_tables.append(table_name)
4043
elif table_name.split(separator, 1)[0] == table_name_wildcard.split("*", 1)[0]:
4144
matching_tables.append(table_name)
4245

@@ -58,6 +61,12 @@ def get_restore_table_matches(table_name_wildcard, separator):
5861
for dir_name in dir_list:
5962
if table_name_wildcard == "*":
6063
matching_tables.append(dir_name)
64+
elif separator == None:
65+
if dir_name.startswith(table_name_wildcard.split("*", 1)[0]):
66+
matching_tables.append(dir_name)
67+
elif separator == '':
68+
if dir_name.startswith(re.sub( r"([A-Z])", r" \1", table_name_wildcard.split("*", 1)[0]).split()[0] ):
69+
matching_tables.append(dir_name)
6170
elif dir_name.split(separator, 1)[0] == table_name_wildcard.split("*", 1)[0]:
6271
matching_tables.append(dir_name)
6372

@@ -66,6 +75,9 @@ def get_restore_table_matches(table_name_wildcard, separator):
6675
def change_prefix(source_table_name, source_wildcard, destination_wildcard, separator):
6776
source_prefix = source_wildcard.split("*", 1)[0]
6877
destination_prefix = destination_wildcard.split("*", 1)[0]
78+
if separator == '':
79+
if re.sub( r"([A-Z])", r" \1", source_table_name).split()[0] == source_prefix:
80+
return destination_prefix + re.sub( r"([A-Z])", r" \1", source_table_name).split(' ',1)[1].replace(" ", "")
6981
if source_table_name.split(separator, 1)[0] == source_prefix:
7082
return destination_prefix + separator + source_table_name.split(separator, 1)[1]
7183

0 commit comments

Comments
 (0)