summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2011-02-23 13:04:21 +0000
committerLars Wirzenius <liw@liw.fi>2011-02-23 13:04:21 +0000
commit3f27dc7988d714561e014c7c1c469969f17a69b8 (patch)
treed21ee5573d05708bab538c20517ac74dc5b2a660
parentceaab8c3e88d01ef272584e94fe44a5ba95b86e0 (diff)
downloadobnam-3f27dc7988d714561e014c7c1c469969f17a69b8.tar.gz
Add force-lock command.
-rw-r--r--obnam.17
-rw-r--r--obnamlib/plugins/force_lock_plugin.py56
-rw-r--r--without-tests1
3 files changed, 64 insertions, 0 deletions
diff --git a/obnam.1 b/obnam.1
index 8acb0f8a..b3a52fa5 100644
--- a/obnam.1
+++ b/obnam.1
@@ -90,6 +90,13 @@ checks the internal consistency of the backup repository.
It verifies that all clients, generations, directories, files, and
all file contents still exists in the backup repository.
It may take quite a long time to run.
+.IP \(bu
+.B force-lock
+removes a lock file for a client in the repository.
+You should only force a lock if you are sure no-one is accessing that
+client's data in the repository.
+A dangling lock might happen, for example, if obnam loses its network
+connection to the backup repository.
.SS "Making backups"
When you run a backup,
.B obnam
diff --git a/obnamlib/plugins/force_lock_plugin.py b/obnamlib/plugins/force_lock_plugin.py
new file mode 100644
index 00000000..83368fd9
--- /dev/null
+++ b/obnamlib/plugins/force_lock_plugin.py
@@ -0,0 +1,56 @@
+# Copyright (C) 2009, 2010, 2011 Lars Wirzenius
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+
+import logging
+import os
+
+import obnamlib
+
+
+class ForceLockPlugin(obnamlib.ObnamPlugin):
+
+ def enable(self):
+ self.app.register_command('force-lock', self.force_lock)
+
+ def force_lock(self, args):
+ self.app.config.require('repository')
+ self.app.config.require('client-name')
+
+ repourl = self.app.config['repository']
+ client_name = self.app.config['client-name']
+ logging.info('Forcing lock')
+ logging.info('Repository: %s' % repourl)
+ logging.info('Client: %s' % client_name)
+
+ repofs = self.app.fsf.new(repourl)
+ repofs.connect()
+ repo = obnamlib.Repository(repofs, self.app.config['node-size'],
+ self.app.config['upload-queue-size'],
+ self.app.config['lru-size'])
+
+ if client_name not in repo.list_clients():
+ logging.warning('Client does not exist in repository.')
+ return
+
+ client_id = repo.clientlist.get_client_id(client_name)
+ client_dir = repo.client_dir(client_id)
+ lockname = os.path.join(client_dir, 'lock')
+ if repofs.exists(lockname):
+ logging.info('Removing lockfile %s' % lockname)
+ repofs.remove(lockname)
+ else:
+ logging.info('Client is not locked')
+
diff --git a/without-tests b/without-tests
index 54da2fe6..844b9e49 100644
--- a/without-tests
+++ b/without-tests
@@ -18,6 +18,7 @@
./obnamlib/plugins/fsck_plugin.py
./obnamlib/plugins/vfs_local_plugin.py
./obnamlib/plugins/sftp_plugin.py
+./obnamlib/plugins/force_lock_plugin.py
./obnamlib/plugins/__init__.py
./obnamlib/repo_tree.py