Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

timvaillancourt
Copy link
Contributor

@timvaillancourt timvaillancourt commented Jun 17, 2016

Added exclusive lock capabilities after seeing it is possible for many processes to overlap each other. Lock is acquired at beginning of backup run and is released on success and failure (inside the exception handler). Lock file path is overridable.

Example logging + backup running:

$ mongodb-consistent-backup -v -c /etc/rdba/percona-backup-mongo.yml 
[2016-06-17 16:32:41,863] [DEBUG] [MainProcess] [DB:connect:20] Getting MongoDB connection to centos7-mongos1:27017
[2016-06-17 16:32:41,874] [DEBUG] [MainProcess] [Lock:acquire:17] Acquired exclusive lock on file: /tmp/mongodb-consistent-backup.lock
[2016-06-17 16:32:41,874] [INFO] [MainProcess] [Backup:run:184] Starting backup of centos7-mongos1:27017 in sharded mode
…
…
[2016-06-17 16:34:33,840] [INFO] [MainProcess] [Archiver:run:102] Archiver threads completed
[2016-06-17 16:34:33,840] [DEBUG] [MainProcess] [Lock:release:26] Releasing exclusive lock on file: /tmp/mongodb-consistent-backup.lock
[2016-06-17 16:34:33,840] [INFO] [MainProcess] [Backup:run:303] Backup completed in 111.988605022 sec

Output if you try to run another backup at the same time:

[tim@centos7 ~]$ mongodb-consistent-backup -v -c /etc/rdba/percona-backup-mongo.yml
[2016-06-17 16:32:45,088] [DEBUG] [MainProcess] [DB:connect:20] Getting MongoDB connection to centos7-mongos1:27017
[2016-06-17 16:32:45,095] [DEBUG] [MainProcess] [Lock:acquire:20] Error acquiring lock on file: /tmp/mongodb-consistent-backup.lock
[2016-06-17 16:32:45,095] [CRITICAL] [MainProcess] [Backup:run:159] Could not acquire lock! Is another mongodb-consistent-backup process running? Exiting

@dbmurphy dbmurphy merged commit 47b617f into Percona-Lab:master Jun 20, 2016
@timvaillancourt timvaillancourt deleted the lock_file branch June 20, 2016 10:08
dbmurphy pushed a commit that referenced this pull request Feb 22, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants