Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

114 lines (93 sloc) 3.761 kb
import os, sys
import time
import errno
import fcntl
import logging
from holland.core.command import Command, option
from holland.core.backup import backup
from holland.core.exceptions import BackupError
from holland.core.config import hollandcfg
from holland.core.spool import spool
from holland.core.util.fmt import format_interval
LOGGER = logging.getLogger(__name__)
class Backup(Command):
Backup the specified backupsets or all
active backupsets specified in holland.conf
name = 'backup'
aliases = [
options = [
option('--abort-immediately', action='store_true',
help="Abort on the first backupset that fails."),
option('--dry-run', '-n', action='store_true',
help="Print backup commands without executing them."),
option('--no-lock', '-f', action='store_true',
help="Run even if another copy of Holland is running.")
description = 'Run backups for active backupsets'
def run(self, cmd, opts, *backupsets):
if not backupsets:
backupsets = hollandcfg.lookup('holland.backupsets')
# strip empty items from backupsets list
backupsets = filter(lambda x: x, backupsets)"-----> Starting backup run <----")
if not backupsets:"No backupsets defined. Please specify in %s or "
"specify a name of a backupset in %s",
os.path.join(os.path.dirname(hollandcfg.filename), 'backupsets'))
return 1
spool.base_path = hollandcfg.lookup('holland.backup-directory')
config_file = open(hollandcfg.filename, 'r')
fcntl.flock(config_file, fcntl.LOCK_EX|fcntl.LOCK_NB)"Acquired backup lock.")
except IOError, exc:"Another holland backup appears already be running.")
if opts.no_lock:"Continuing due to --no-lock")
return 1
error_found = 0
start_time = time.time()
for jobname in backupsets:
error_found |= run_backup(jobname, opts.dry_run)
if error_found and opts.abort_immediately:"Aborting as --abort-immediately is set")
if not opts.no_lock:
fcntl.flock(config_file, fcntl.LOCK_UN)
except OSError, exc:
LOGGER.debug("Error when releasing backup lock: %s", exc)
if not error_found:"All backupsets run successfully")
else:"One or more backupsets failed to run successfully")"This backup run of %d backupset%s took %s",
len(backupsets), ('','s')[len(backupsets) > 1],
format_interval(time.time() - start_time))"-----> Ending backup run <----")
return error_found
def run_backup(jobname, dry_run=False):
backup(jobname, dry_run)
except KeyboardInterrupt, e:"Interrupt")
except BackupError, exc:
LOGGER.error("Backup %r failed: %s", jobname, exc)
except Exception, exc:
LOGGER.error("Unexpected exception caught. This is probably "
"a bug. Please report to the holland "
"development team.", exc_info=True)
return 0
return 1
Jump to Line
Something went wrong with that request. Please try again.