Exemplo n.º 1
0
    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)

        LOGGER.info("-----> Starting backup run <----")
        if not backupsets:
            LOGGER.info("No backupsets defined.  Please specify in %s or "
                        "specify a name of a backupset in %s",
                        hollandcfg.filename,
                        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')
        try:
            fcntl.flock(config_file, fcntl.LOCK_EX|fcntl.LOCK_NB)
            LOGGER.info("Acquired backup lock.")
        except IOError, exc:
            LOGGER.info("Another holland backup appears already be running.")

            if opts.no_lock:
                LOGGER.info("Continuing due to --no-lock")
            else:
                LOGGER.info("Aborting")
                return 1
Exemplo n.º 2
0
def setup_logging(opts):
    clear_root_handlers()
    if hasattr(opts, "log_level"):
        log_level = opts.log_level or hollandcfg.lookup("logging.level")
    else:
        log_level = hollandcfg.lookup("logging.level")

    if os.isatty(sys.stdin.fileno()) and not opts.quiet:
        setup_console_logging(level=log_level)

    if hollandcfg.lookup("logging.filename"):
        try:
            setup_file_logging(filename=str(hollandcfg.lookup("logging.filename")), level=log_level)
        except IOError, exc:
            LOGGER.warn("Skipping file logging: %s", exc)
Exemplo n.º 3
0
def bootstrap(opts):
    # Setup the configuration
    setup_config(opts)
    # use umask setting
    setup_umask()
    # Setup logging per config
    setup_logging(opts)
    # setup tmpdir
    if hollandcfg.lookup('holland.tmpdir'):
        os.environ['TMPDIR'] = str(hollandcfg.lookup('holland.tmpdir'))
    # configure our PATH
    setup_path()
    # Setup plugin directories
    setup_plugins()
    # Setup spool
    spool.path = hollandcfg.lookup('holland.backup-directory')
Exemplo n.º 4
0
def bootstrap(opts):
    # Setup the configuration
    setup_config(opts)
    # use umask setting
    setup_umask()
    # Setup logging per config
    setup_logging(opts)
    # setup tmpdir
    if hollandcfg.lookup('holland.tmpdir'):
        os.environ['TMPDIR'] = str(hollandcfg.lookup('holland.tmpdir'))
    # configure our PATH
    setup_path()
    # Setup plugin directories
    setup_plugins()
    # Setup spool
    spool.path = hollandcfg.lookup('holland.backup-directory')
Exemplo n.º 5
0
    def run(self, cmd, opts, *backups):
        error = 0

        if not backups:
            LOG.info("No backupsets specified - using backupsets from %s",
                     hollandcfg.filename)
            backups = hollandcfg.lookup('holland.backupsets')

        if not backups:
            LOG.warn("Nothing to purge")
            return 0

        if not opts.force:
            LOG.warn("Running in dry-run mode.  Use --execute to do a real purge.")

        for name in backups:
            if '/' not in name:
                backupset = spool.find_backupset(name)
                if not backupset:
                    LOG.error("Failed to find backupset '%s'", name)
                    error = 1
                    continue
                purge_backupset(backupset, opts.force, opts.all)
            else:
                backup = spool.find_backup(name)
                if not backup:
                    LOG.error("Failed to find single backup '%s'", name)
                    error = 1
                    continue
                purge_backup(backup, opts.force)
                if opts.force:
                    spool.find_backupset(backup.backupset).update_symlinks()
        return error
Exemplo n.º 6
0
def setup_logging(opts):
    clear_root_handlers()
    if hasattr(opts, 'log_level'):
        log_level = opts.log_level or hollandcfg.lookup('logging.level')
    else:
        log_level = hollandcfg.lookup('logging.level')

    if (not opts.quiet):
        setup_console_logging(level=log_level)

    if hollandcfg.lookup('logging.filename'):
        try:
            setup_file_logging(filename=str(hollandcfg.lookup('logging.filename')),
                               level=log_level)
        except IOError, exc:
            LOGGER.warn("Skipping file logging: %s", exc)
Exemplo n.º 7
0
    def run(self, cmd, opts, *backups):
        error = 0

        if not backups:
            LOG.info("No backupsets specified - using backupsets from %s",
                     hollandcfg.filename)
            backups = hollandcfg.lookup('holland.backupsets')

        if not backups:
            LOG.warn("Nothing to purge")
            return 0

        if not opts.force:
            LOG.warn(
                "Running in dry-run mode.  Use --execute to do a real purge.")

        for name in backups:
            if '/' not in name:
                backupset = spool.find_backupset(name)
                if not backupset:
                    LOG.error("Failed to find backupset '%s'", name)
                    error = 1
                    continue
                purge_backupset(backupset, opts.force, opts.all)
            else:
                backup = spool.find_backup(name)
                if not backup:
                    LOG.error("Failed to find single backup '%s'", name)
                    error = 1
                    continue
                purge_backup(backup, opts.force)
                if opts.force:
                    spool.find_backupset(backup.backupset).update_symlinks()
        return error
Exemplo n.º 8
0
def setup_logging(opts):
    clear_root_handlers()
    if hasattr(opts, 'log_level'):
        log_level = opts.log_level or hollandcfg.lookup('logging.level')
    else:
        log_level = hollandcfg.lookup('logging.level')

    if (not opts.quiet):
        setup_console_logging(level=log_level)

    if hollandcfg.lookup('logging.filename'):
        try:
            setup_file_logging(filename=str(
                hollandcfg.lookup('logging.filename')),
                               level=log_level)
        except IOError, exc:
            LOGGER.warn("Skipping file logging: %s", exc)
Exemplo n.º 9
0
def setup_logging(opts):
    clear_root_handlers()
    if hasattr(opts, 'log_level'):
        log_level = opts.log_level or hollandcfg.lookup('logging.level')
    else:
        log_level = hollandcfg.lookup('logging.level')

    if (os.isatty(sys.stdin.fileno()) and not opts.quiet):
        setup_console_logging(level=log_level)

    if hollandcfg.lookup('logging.filename'):
        setup_file_logging(filename=hollandcfg.lookup('logging.filename'),
                           level=log_level)

    # Monkey patch in routing warnings through logging
    old_showwarning = warnings.showwarning
    warnings.showwarning = log_warnings
Exemplo n.º 10
0
def setup_logging(opts):
    clear_root_handlers()
    if hasattr(opts, 'log_level'):
        log_level = opts.log_level or hollandcfg.lookup('logging.level')
    else:
        log_level = hollandcfg.lookup('logging.level')

    if (not opts.quiet):
        setup_console_logging(level=log_level)

    if hollandcfg.lookup('logging.filename'):
        try:
            if hollandcfg.lookup('logging.format'):
                setup_file_logging(
                    filename=str(hollandcfg.lookup('logging.filename')),
                    level=log_level,
                    format=hollandcfg.lookup(str('logging.format')))
            else:
                setup_file_logging(filename=str(
                    hollandcfg.lookup('logging.filename')),
                                   level=log_level)
        except IOError as exc:
            LOGGER.warn("Skipping file logging: %s", exc)

    # Monkey patch in routing warnings through logging
    old_showwarning = warnings.showwarning
    warnings.showwarning = log_warnings
Exemplo n.º 11
0
def bootstrap(opts):
    # Setup the configuration
    setup_config(opts)
    # Setup logging per config
    setup_logging(opts)
    # use umask setting
    setup_umask()
    # configure our PATH
    setup_path()
    # Setup plugin directories
    setup_plugins()
    # Setup spool
    spool.path = hollandcfg.lookup('holland.backup-directory')
Exemplo n.º 12
0
    def test_globalconfig(self):
        import logging
        cfgentry_tests = {
            'holland.plugin-dirs' : ['/usr/share/holland/plugins'],
            'holland.umask' : int('0007', 8),
            'holland.path' : '/bin:/usr/bin:/usr/local/bin:/usr/local/sbin:/usr/local/mysql/bin',

            'logging.level' : logging.INFO,
            'logging.filename' : '/dev/null'
        }

        for key, value in cfgentry_tests.items():
            self.assertEqual(hollandcfg.lookup(key), value)
Exemplo n.º 13
0
    def test_globalconfig(self):
        import logging
        cfgentry_tests = {
            'holland.plugin-dirs': ['/usr/share/holland/plugins'],
            'holland.umask': int('0007', 8),
            'holland.path':
            '/bin:/usr/bin:/usr/local/bin:/usr/local/sbin:/usr/local/mysql/bin',
            'logging.level': logging.INFO,
            'logging.filename': '/dev/null'
        }

        for key, value in list(cfgentry_tests.items()):
            self.assertEqual(hollandcfg.lookup(key), value)
Exemplo n.º 14
0
def setup_path():
    if hollandcfg.lookup('holland.path'):
        os.putenv('PATH', hollandcfg.lookup('holland.path'))
        os.environ['PATH'] = hollandcfg.lookup('holland.path')
Exemplo n.º 15
0
def setup_plugins():
    map(add_plugin_dir, hollandcfg.lookup('holland.plugin-dirs'))
Exemplo n.º 16
0
def setup_path():
    if hollandcfg.lookup('holland.path'):
        os.putenv('PATH', hollandcfg.lookup('holland.path'))
        os.environ['PATH'] = hollandcfg.lookup('holland.path')
Exemplo n.º 17
0
def setup_umask():
    os.umask(hollandcfg.lookup('holland.umask'))
Exemplo n.º 18
0
def setup_plugins():
    map(add_plugin_dir, hollandcfg.lookup('holland.plugin-dirs'))
Exemplo n.º 19
0
    def run(self, cmd, opts, *backupsets):
        if not backupsets:
            backupsets = hollandcfg.lookup('holland.backupsets')

        # strip empty items from backupsets list
        backupsets = [name for name in backupsets if name]

        if not backupsets:
            LOG.info("Nothing to backup")
            return 1

        runner = BackupRunner(spool)

        # dry-run implies no-lock
        if opts.dry_run:
            opts.no_lock = True

        # don't purge if doing a dry-run, or when simultaneous backups may be running
        if not opts.no_lock:
            purge_mgr = PurgeManager()

            runner.register_cb('before-backup', purge_mgr)
            runner.register_cb('after-backup', purge_mgr)
            runner.register_cb('failed-backup', purge_backup)

        runner.register_cb('after-backup', report_low_space)

        if not opts.dry_run:
            runner.register_cb('before-backup', call_hooks)
            runner.register_cb('after-backup', call_hooks)
            runner.register_cb('failed-backup', call_hooks)

        error = 1
        LOG.info("--- Starting %s run ---", opts.dry_run and 'dry' or 'backup')
        for name in backupsets:
            try:
                config = hollandcfg.backupset(name)
                # ensure we have at least an empty holland:backup section
                config.setdefault('holland:backup', {})
            except (SyntaxError, IOError), exc:
                LOG.error("Could not load backupset '%s': %s", name, exc)
                break

            if not opts.no_lock:
                lock = Lock(config.filename)
                try:
                    lock.acquire()
                    LOG.debug("Set advisory lock on %s", lock.path)
                except LockError:
                    LOG.debug("Unable to acquire advisory lock on %s",
                              lock.path)
                    LOG.error("Another holland backup process is already "
                              "running backupset '%s'. Aborting.", name)
                    break

            try:
                try:
                    runner.backup(name, config, opts.dry_run)
                except BackupError, exc:
                    LOG.error("Backup failed: %s", exc.args[0])
                    break
                except ConfigError, exc:
                    break
Exemplo n.º 20
0
def setup_path():
    if hollandcfg.lookup("holland.path"):
        os.putenv("PATH", hollandcfg.lookup("holland.path"))
        os.environ["PATH"] = hollandcfg.lookup("holland.path")
Exemplo n.º 21
0
def setup_plugins():
    for location in hollandcfg.lookup('holland.plugin-dirs'):
        add_plugin_dir(location)
Exemplo n.º 22
0
def setup_umask():
    os.umask(hollandcfg.lookup("holland.umask"))
Exemplo n.º 23
0
    def run(self, cmd, opts, *backupsets):
        if not backupsets:
            backupsets = hollandcfg.lookup('holland.backupsets')

        # strip empty items from backupsets list
        backupsets = [name for name in backupsets if name]

        if not backupsets:
            LOG.info("Nothing to backup")
            return 1

        runner = BackupRunner(spool)

        # dry-run implies no-lock
        if opts.dry_run:
            opts.no_lock = True

        # don't purge if doing a dry-run, or when simultaneous backups may be running
        if not opts.no_lock:
            purge_mgr = PurgeManager()

            runner.register_cb('pre-backup', purge_mgr)
            runner.register_cb('post-backup', purge_mgr)
            runner.register_cb('backup-failure', purge_backup)

        runner.register_cb('post-backup', report_low_space)

        runner.register_cb('pre-backup', call_hooks)
        runner.register_cb('post-backup', call_hooks)
        runner.register_cb('backup-failure', call_hooks)

        error = 1
        LOG.info("--- Starting %s run ---", opts.dry_run and 'dry' or 'backup')
        for name in backupsets:
            try:
                config = hollandcfg.backupset(name)
                # ensure we have at least an empty holland:backup section
                config.setdefault('holland:backup', {})
            except (SyntaxError, IOError), exc:
                LOG.error("Could not load backupset '%s': %s", name, exc)
                break

            if not opts.no_lock:
                lock = Lock(config.filename)
                try:
                    lock.acquire()
                    LOG.info("Acquired lock %s : '%s'", lock.path, lock.lock.name)
                except LockError:
                    LOG.error("Failed to acquire lock on backupset %s (%s)",
                                name, config.filename)

                    break

            try:
                try:
                    runner.backup(name, config, opts.dry_run)
                except BackupError, exc:
                    LOG.error("Backup failed: %s", exc.args[0])
                    break
                except ConfigError, exc:
                    break
Exemplo n.º 24
0
    def run(self, cmd, opts, *backupsets):
        if not backupsets:
            backupsets = hollandcfg.lookup("holland.backupsets")

        # strip empty items from backupsets list
        backupsets = [name for name in backupsets if name]

        if not backupsets:
            LOG.info("Nothing to backup")
            return 1

        runner = BackupRunner(spool)

        # dry-run implies no-lock
        if opts.dry_run:
            opts.no_lock = True

        # don't purge if doing a dry-run, or when simultaneous backups may be running
        if not opts.no_lock:
            purge_mgr = PurgeManager()

            runner.register_cb("before-backup", purge_mgr)
            runner.register_cb("after-backup", purge_mgr)
            runner.register_cb("failed-backup", purge_backup)

        runner.register_cb("after-backup", report_low_space)

        if not opts.dry_run:
            runner.register_cb("before-backup", call_hooks)
            runner.register_cb("after-backup", call_hooks)
            runner.register_cb("failed-backup", call_hooks)

        error = 1
        LOG.info("--- Starting %s run ---", opts.dry_run and "dry" or "backup")
        for name in backupsets:
            try:
                config = hollandcfg.backupset(name)
                # ensure we have at least an empty holland:backup section
                config.setdefault("holland:backup", {})
            except (SyntaxError, IOError), exc:
                LOG.error("Could not load backupset '%s': %s", name, exc)
                break

            if not opts.no_lock:
                lock = Lock(config.filename)
                try:
                    lock.acquire()
                    LOG.debug("Set advisory lock on %s", lock.path)
                except LockError:
                    LOG.debug("Unable to acquire advisory lock on %s", lock.path)
                    LOG.error("Another holland backup process is already " "running backupset '%s'. Aborting.", name)
                    break

            try:
                try:
                    runner.backup(name, config, opts.dry_run)
                except BackupError, exc:
                    LOG.error("Backup failed: %s", exc.args[0])
                    break
                except ConfigError, exc:
                    break
Exemplo n.º 25
0
def setup_umask():
    os.umask(hollandcfg.lookup('holland.umask'))