Skip to content

Commit 20071f6

Browse files
Updated cnf file, fix mongodump ignoring thread count, fix log rotation
1 parent 3c1b923 commit 20071f6

File tree

10 files changed

+66
-58
lines changed

10 files changed

+66
-58
lines changed
Lines changed: 38 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,50 @@
11
production:
22
host: localhost
33
port: 27017
4-
#username:
5-
#password:
6-
#authdb: admin
7-
log_dir: /tmp
4+
#username: [auth username] (default: none)
5+
#password: [auth password] (default: none)
6+
#authdb: [auth database] (default: admin)
7+
log_dir: /var/log/mongodb-consistent-backup
88
backup:
99
method: mongodump
1010
name: default
11-
location: /opt/mongodb/backup
12-
mongodump:
13-
binary: /usr/bin/mongodump
14-
# compression: gzip (default: true - if supported)
15-
replication:
16-
max_lag_secs: 5
17-
min_priority: 0
18-
max_priority: 1000
19-
hidden_only: false
20-
sharding:
21-
balancer:
22-
wait_secs: 300
23-
ping_secs: 3
24-
oplog:
25-
#compression: gzip
26-
#resolver_threads: 4
11+
location: /var/lib/mongodb-consistent-backup
12+
# mongodump:
13+
# binary: [path] (default: /usr/bin/mongodump)
14+
# compression: [none|gzip] (default: true - if supported)
15+
# threads: [1-16] (default: auto-generated - shards/cpu)
16+
#replication:
17+
# max_lag_secs: [1+] (default: 5)
18+
# min_priority: [0-999] (default: 0)
19+
# max_priority: [2-1000] (default: 1000)
20+
# hidden_only: [true|false] (default: false)
21+
#sharding:
22+
# balancer:
23+
# wait_secs: [1+] (default: 300)
24+
# ping_secs: [1+] (default: 3)
25+
#oplog:
26+
# compression: [none|gzip] (default: true - if used by backup stage)
27+
# resolver_threads: [1+] (default: 2 per CPU)
28+
# tailer:
29+
# status_interval: 30
2730
archive:
2831
method: tar
29-
#tar:
30-
# compression: gzip
31-
# threads: 2
32+
# tar:
33+
# compression: [none|gzip] (default: gzip, none if backup is compressed)
34+
# threads: [1+] (default: 1 per CPU)
3235
notify:
3336
method: none
34-
#nsca:
35-
# server: localhost:5667
36-
# password: secret
37-
# check_host: localhost
38-
# check_name: mongodb_consistent_backup
37+
# nsca:
38+
# server: [host:port] (default: localhost:5667)
39+
# password: [password]
40+
# check_host: [nagios host]
41+
# check_name: [nagios check name]
3942
upload:
4043
method: none
41-
remove_uploaded: false
42-
#s3:
43-
# access_key: <AWS S3 Access Key>
44-
# secret_key: <AWS S3 Secret Key>
45-
# bucket_name: <AWS S3 Bucket Name>
46-
# bucket_prefix: /
47-
# threads: 4
44+
# remove_uploaded: [true|false] (default: false)
45+
# s3:
46+
# access_key: [AWS S3 Access Key]
47+
# secret_key: [AWS S3 Secret Key]
48+
# bucket_name: [AWS S3 Bucket Name]
49+
# bucket_prefix: [prefix] (default: /)
50+
# threads: [1+] (default: 1 per CPU)

mongodb_consistent_backup/Archive/Tar/Tar.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def _reduce_method(m):
2424
class Tar(Task):
2525
def __init__(self, manager, config, timer, base_dir, backup_dir, **kwargs):
2626
super(Tar, self).__init__(self.__class__.__name__, manager, config, timer, base_dir, backup_dir, **kwargs)
27-
self.compression_method = self.config.archive.tar.compression
27+
self.compression_method = self.config.archive.tar.compression
2828
self.binary = "tar"
2929

3030
self._pool = None

mongodb_consistent_backup/Backup/Mongodump/Mongodump.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,16 @@ def __init__(self, manager, config, timer, base_dir, backup_dir, replsets, shard
2626
self.replsets = replsets
2727
self.sharding = sharding
2828

29+
self.version = 'unknown'
2930
self.threads_max = 16
3031
self.config_replset = False
3132
self.dump_threads = []
3233
self.states = {}
3334
self._summary = {}
3435

36+
if self.config.backup.mongodump.threads and self.config.backup.mongodump.threads > 0:
37+
self.threads(self.config.backup.mongodump.threads)
38+
3539
with hide('running', 'warnings'), settings(warn_only=True):
3640
self.version = local("%s --version|awk 'NR >1 {exit}; /version/{print $NF}'" % self.binary, capture=True)
3741

mongodb_consistent_backup/Backup/Mongodump/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,7 @@ def config(parser):
77
parser.add_argument("--backup.mongodump.compression", dest="backup.mongodump.compression",
88
help="Compression method to use on backup (default: gzip)", default="gzip",
99
choices=["none", "gzip"])
10+
parser.add_argument("--backup.mongodump.threads", dest="backup.mongodump.threads",
11+
help="Number of threads to use for each mongodump process. There is 1 x mongodump per shard, be careful! (default: shards/CPUs)",
12+
default=0, type=int)
1013
return parser

mongodb_consistent_backup/Logger.py

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ def start(self):
3434
self.file_log.setLevel(self.log_level)
3535
self.file_log.setFormatter(logging.Formatter(self.log_format))
3636
logging.getLogger('').addHandler(self.file_log)
37+
print "update_symlink()"
38+
self.update_symlink()
3739
except OSError, e:
3840
logging.warning("Could not start file log handler, writing to stdout only")
3941
pass
@@ -42,11 +44,12 @@ def close(self):
4244
if self.file_log:
4345
self.file_log.close()
4446

45-
def compress_last(self):
47+
def compress(self):
4648
gz_log = None
4749
try:
48-
if not os.path.isfile(self.last_log):
50+
if not os.path.isfile(self.last_log) or self.last_log == self.backup_log_file:
4951
return
52+
logging.info("Compressing previous log file")
5053
gz_file = "%s.gz" % self.last_log
5154
gz_log = GzipFile(gz_file, "w+")
5255
with open(self.last_log) as f:
@@ -57,13 +60,13 @@ def compress_last(self):
5760
if gz_log:
5861
gz_log.close()
5962

63+
def update_symlink(self):
64+
if os.path.islink(self.current_log_file):
65+
self.last_log = os.readlink(self.current_log_file)
66+
os.remove(self.current_log_file)
67+
os.symlink(self.backup_log_file, self.current_log_file)
68+
6069
def rotate(self):
61-
if self.do_file_log:
62-
if os.path.islink(self.current_log_file):
63-
logging.info("Rotating previous log file")
64-
self.last_log = os.readlink(self.current_log_file)
65-
if self.last_log == self.backup_log_file:
66-
return
67-
os.remove(self.current_log_file)
68-
self.compress_last()
69-
os.symlink(self.backup_log_file, self.current_log_file)
70+
if self.do_file_log and self.last_log:
71+
logging.info("Running rotation of log files")
72+
self.compress()

mongodb_consistent_backup/Oplog/Tailer/TailThread.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616

1717
class TailThread(Process):
18-
def __init__(self, do_stop, uri, config, timer, oplog_file, state, dump_gzip=False, status_secs=15):
18+
def __init__(self, do_stop, uri, config, timer, oplog_file, state, dump_gzip=False, status_secs=30):
1919
Process.__init__(self)
2020
self.do_stop = do_stop
2121
self.uri = uri

mongodb_consistent_backup/Oplog/Tailer/Tailer.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@
1414

1515

1616
class Tailer(Task):
17-
def __init__(self, manager, config, timer, base_dir, backup_dir, replsets, status_secs=15):
17+
def __init__(self, manager, config, timer, base_dir, backup_dir, replsets):
1818
super(Tailer, self).__init__(self.__class__.__name__, manager, config, timer, base_dir, backup_dir)
1919
self.backup_name = self.config.name
2020
self.user = self.config.username
2121
self.password = self.config.password
2222
self.authdb = self.config.authdb
23+
self.status_secs = self.config.oplog.tailer.status_interval
2324
self.replsets = replsets
24-
self.status_secs = status_secs
2525

2626
self.shards = {}
2727
self._summary = {}

mongodb_consistent_backup/Oplog/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66

77
def config(parser):
8-
parser.add_argument("--oplog.resolver.threads", dest="oplog.resolver.threads", help="Number of threads to use during resolver step (default: 1-per-CPU)", default=0, type=int)
98
parser.add_argument("--oplog.compression", dest="oplog.compression", help="Compression method to use on captured oplog file (default: none)", choices=["none","gzip"], default="none")
9+
parser.add_argument("--oplog.resolver.threads", dest="oplog.resolver.threads", help="Number of threads to use during resolver step (default: 1-per-CPU)", default=0, type=int)
10+
parser.add_argument("--oplog.tailer.status_interval", dest="oplog.tailer.status_interval", help="Number of seconds to wait between reporting oplog tailer status (default: 30)", default=30, type=int)
1011
return parser

mongodb_consistent_backup/Pipeline/Task.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ def __init__(self, task_name, manager, config, timer, base_dir, backup_dir, **kw
2323
self.completed = False
2424
self.exit_code = 255
2525

26+
self.thread_count = None
2627
self.cpu_count = cpu_count()
2728
self.compression_method = 'none'
28-
self.thread_count = 1
2929
self.timer_name = self.__class__.__name__
3030

3131
signal(SIGINT, SIG_IGN)

scripts/mongodb_consistent_backup.spec

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,6 @@ install -m 0644 %{SOURCE3} %{buildroot}/usr/share/%{name}/README.rst
5151
#0 0 * * * %{run_user} /usr/bin/mongodb-consistent-backup --config=/etc/mongodb-consistent-backup.yml >/dev/null 2>&1
5252
EOF
5353

54-
# Change /etc config file to use rpm paths for logs and data
55-
sed -i \
56-
-e s@log_dir:\ /tmp@log_dir:\ %{log_dir}@g \
57-
-e s@location:\ /opt/mongodb/backup@location:\ %{data_dir}@g \
58-
%{buildroot}%{_sysconfdir}/%{bin_name}.yml
59-
6054

6155
%pre
6256
/usr/bin/getent group %{run_group} >/dev/null 2>&1 || /usr/sbin/groupadd -r %{run_group}

0 commit comments

Comments
 (0)