1 # -*- mode: python; sh-basic-offset: 4; indent-tabs-mode: nil; -*-
2 # vim: set filetype=python sw=4 sts=4 expandtab autoindent:
4 # Backupninja python reimplementation, based on original backupninja program
6 # Copyright (C) 2010 Matthijs Kooijman <matthijs@stdin.nl>
8 # This program is free software; you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 2 of the License, or
11 # (at your option) any later version.
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License along
19 # with this program; if not, write to the Free Software Foundation, Inc.,
20 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 """ Running backup actions """
28 from backupninja import config
29 from backupninja import handlers
31 def run_all_actions(opts, global_config):
33 Run all defined actions.
35 opts are the parsed commandline options, global_config is the parsed
38 log.info('Running all actions')
40 action_configs = config.list_actions(opts)
42 log.critical('Unable to list actions: %s', e)
47 for action_config in action_configs:
48 run_action(action_config, opts, global_config)
50 def run_action(action_config, opts, global_config):
52 Run a single action. action_config is the full path to its
53 configuration file. opts are the parsed commandline options,
54 global_config is the parsed global configuration.
56 config_name = os.path.basename(action_config)
57 # Split the action filename
58 parts = os.path.basename(config_name).split('.')
60 log.error('Invalid action filename: "%s". Should be in the form name.type, where type is a valid handler.' % action_config)
62 (action_name, action_ty) = parts
64 action_log = logging.getLogger(config_name)
65 action_log.info('Running')
68 # Create a handler for this action
69 action = handlers.create_action(action_ty, logger=action_log)
70 # Let the handler load its configuration file
71 action.load_config(action_config)
73 action.run(test=opts.test)
74 action.finish(test=opts.test)
75 # Ask the action if there where any failures
76 success = not action.failed
78 action_log.error('Unexpected exception: %s', e)
80 log.debug(traceback.format_exc())
84 action_log.info('Succeeded')
86 action_log.info('Failed')