summaryrefslogtreecommitdiff
diff options
authorStuart Bishop <stuart@stuartbishop.net>2017-03-06 20:32:41 +0700
committerStuart Bishop <stuart@stuartbishop.net>2017-03-06 20:32:41 +0700
commit82c9f427f8a030cc4180919c6e1b54878f5e94bc (patch)
treef50fc39162e408391650dccfaf32c73be9134f0a
parentf41e22bfe7dd941b27933df4eeb744dbc8eac05f (diff)
parentf4329a97b94813ef9bcf465b0887974ce8ac8183 (diff)
[evarlast,r=stub] Warn about unexpected entries in backupdir, rather than crash
-rwxr-xr-xhooks/hooks.py2
-rwxr-xr-xtemplates/backup.py.tpl12
2 files changed, 11 insertions, 3 deletions
diff --git a/hooks/hooks.py b/hooks/hooks.py
index 254fca3..731444d 100755
--- a/hooks/hooks.py
+++ b/hooks/hooks.py
@@ -865,7 +865,7 @@ def restart_mongod(wait_for=default_wait_for, max_tries=default_max_tries):
def backup_cronjob(disable=False):
- """Generate the cronjob to backup with mongodbump."""
+ """Generate the cronjob to backup with mongodump."""
juju_log('Setting up cronjob')
config_data = config()
backupdir = config_data['backup_directory']
diff --git a/templates/backup.py.tpl b/templates/backup.py.tpl
index 024520d..dc461b2 100755
--- a/templates/backup.py.tpl
+++ b/templates/backup.py.tpl
@@ -1,6 +1,7 @@
#!/usr/bin/env python
-"""Generate the cronjob to backup with mongodbump."""
+"""Generate the cronjob to backup with mongodump."""
+import logging
from os import chdir
from os import listdir
from os import remove
@@ -11,6 +12,9 @@ from shutil import rmtree
import subprocess
from tempfile import mkdtemp
+logging.basicConfig()
+# use backup.py as logger name because __name__ will be __main__
+logger = logging.getLogger('backup.py')
when = datetime.now()
backupdir = '$backup_directory'
@@ -28,7 +32,11 @@ if not exists(backupdir):
current_backups = listdir(backupdir)
current_backups.sort()
for file in current_backups[0:-$backup_copies]:
- remove(join(backupdir, file))
+ fname = join(backupdir, file)
+ try:
+ remove(fname)
+ except Exception as e:
+ logger.warning("could not remove %s:%s", fname, e)
chdir(tmpdir)