Skip to content

Commit ad47426

Browse files
Merge pull request #86 from timvaillancourt/MCB_1.0-cleanup_v3
Mcb 1.0 cleanup v3
2 parents ac861cd + 8f090d6 commit ad47426

File tree

6 files changed

+39
-16
lines changed

6 files changed

+39
-16
lines changed

mongodb_consistent_backup/Archive/Archive.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import logging
22

33
from Tar import Tar
4+
from mongodb_consistent_backup.Common import config_to_string, parse_submodule
45

56

67
class Archive:
@@ -14,16 +15,18 @@ def __init__(self, config, backup_dir):
1415

1516
def init(self):
1617
archive_method = self.config.archive.method
17-
if not archive_method or archive_method.lower() == "none":
18+
if not archive_method or parse_submodule(archive_method) == "none":
1819
logging.info("Archiving disabled, skipping")
1920
else:
20-
self.method = archive_method.lower()
21+
self.method = parse_submodule(archive_method)
2122
logging.info("Using archiving method: %s" % self.method)
2223
try:
2324
self._archiver = globals()[self.method.capitalize()](
2425
self.config,
2526
self.backup_dir
2627
)
28+
except LookupError, e:
29+
raise Exception, 'No archiving method: %s' % self.method, None
2730
except Exception, e:
2831
raise e
2932

@@ -37,10 +40,8 @@ def threads(self, threads=None):
3740

3841
def archive(self):
3942
if self._archiver:
40-
config_vars = ""
41-
for key in self.config.archive:
42-
config_vars += "%s=%s," % (key, self.config.archive[key])
43-
logging.info("Archiving with method: %s (options: %s)" % (self.method, str(config_vars[:-1])))
43+
config_string = config_to_string(self.config.archive[self.method])
44+
logging.info("Archiving with method: %s (options: %s)" % (self.method, config_string))
4445
return self._archiver.run()
4546

4647
def close(self):

mongodb_consistent_backup/Backup/Backup.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import logging
22

33
from Mongodump import Mongodump
4+
from mongodb_consistent_backup.Common import config_to_string, parse_submodule
45

56

67
class Backup:
@@ -16,17 +17,20 @@ def __init__(self, config, backup_dir, secondaries, config_server=None):
1617

1718
def init(self):
1819
backup_method = self.config.backup.method
19-
if not backup_method or backup_method.lower() == "none":
20+
if not backup_method or parse_submodule(backup_method) == "none":
2021
raise Exception, 'Must specify a backup method!', None
21-
self.method = backup_method.lower()
22-
logging.info("Using backup method: %s" % self.method)
22+
self.method = parse_submodule(backup_method)
23+
config_string = config_to_string(self.config.backup[self.method])
24+
logging.info("Using backup method: %s (options: %s)" % (self.method, config_string))
2325
try:
2426
self._method = globals()[self.method.capitalize()](
2527
self.config,
2628
self.backup_dir,
2729
self.secondaries,
2830
self.config_server
2931
)
32+
except LookupError, e:
33+
raise Exception, 'No backup method: %s' % self.method, None
3034
except Exception, e:
3135
raise Exception, "Problem performing %s! Error: %s" % (self.method, e), None
3236

mongodb_consistent_backup/Common/Util.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
import socket
22

3+
def config_to_string(config):
4+
config_vars = ""
5+
for key in config:
6+
config_vars += "%s=%s," % (key, config[key])
7+
return config_vars[:-1]
8+
9+
def parse_submodule(name):
10+
return name.rstrip().lower()
311

412
def validate_hostname(hostname):
513
try:

mongodb_consistent_backup/Common/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
from DB import DB
33
from LocalCommand import LocalCommand
44
from Lock import Lock
5-
from Util import validate_hostname
5+
from Util import config_to_string, parse_submodule, validate_hostname

mongodb_consistent_backup/Notify/Notify.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
import logging
22

3+
from mongodb_consistent_backup.Common import config_to_string, parse_submodule
4+
5+
36
class Notify:
47
def __init__(self, config):
58
self.config = config
@@ -10,13 +13,16 @@ def __init__(self, config):
1013

1114
def init(self):
1215
notify_method = self.config.notify.method
13-
if not notify_method or notify_method.lower() == "none":
16+
if not notify_method or parse_submodule(notify_method) == "none":
1417
logging.info("Notifying disabled, skipping")
1518
else:
16-
self.method = notify_method.lower()
17-
logging.info("Using notify method: %s" % self.method)
19+
self.method = parse_submodule(notify_method)
20+
config_string = config_to_string(self.config.notify[self.method])
21+
logging.info("Using notify method: %s (options: %s)" % (self.method, config_string))
1822
try:
1923
self._notifier = globals()[self.method.capitalize()](self.config)
24+
except LookupError, e:
25+
raise Exception, 'No notify method: %s' % self.method, None
2026
except Exception, e:
2127
raise e
2228

mongodb_consistent_backup/Upload/Upload.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import logging
22

33
from S3 import S3
4+
from mongodb_consistent_backup.Common import config_to_string, parse_submodule
45

56

67
class Upload:
@@ -15,17 +16,20 @@ def __init__(self, config, base_dir, backup_dir):
1516

1617
def init(self):
1718
upload_method = self.config.upload.method
18-
if not upload_method or upload_method.lower() == "none":
19+
if not upload_method or parse_submodule(upload_method) == "none":
1920
logging.info("Uploading disabled, skipping")
2021
else:
21-
self.method = upload_method.lower()
22-
logging.info("Using upload method: %s" % self.method)
22+
self.method = parse_submodule(upload_method)
23+
config_string = config_to_string(self.config.upload[self.method])
24+
logging.info("Using upload method: %s (options: %s)" % (self.method, config_string))
2325
try:
2426
self._uploader = globals()[self.method.capitalize()](
2527
self.config,
2628
self.base_dir,
2729
self.backup_dir
2830
)
31+
except LookupError, e:
32+
raise Exception, 'No upload method: %s' % self.method, None
2933
except Exception, e:
3034
raise Exception, "Problem settings up %s Uploader Error: %s" % (self.method, e), None
3135

0 commit comments

Comments
 (0)