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 """
27 from backupninja import config
28 from backupninja import handlers
30 def run_all_actions(opts, global_config):
32 Run all defined actions.
34 opts are the parsed commandline options, global_config is the parsed
37 log.info('Running all actions')
39 action_configs = config.list_actions(opts)
41 log.critical('Unable to list actions: %s', e)
46 for action_config in action_configs:
47 run_action(action_config, opts, global_config)
49 def run_action(action_config, opts, global_config):
51 Run a single action. action_config is the full path to its
52 configuration file. opts are the parsed commandline options,
53 global_config is the parsed global configuration.
55 # Split the action filename
56 parts = os.path.basename(action_config).split('.')
58 log.error('Invalid action filename: "%s". Should be in the form name.type, where type is a valid handler.' % action_config)
60 (action_name, action_ty) = parts
61 log.info('Running action "%s.%s"', action_name, action_ty)
64 # Create a handler for this action
65 action = handlers.create_action(action_ty)
66 # Let the handler load its configuration file
67 action.load_config(action_config)
69 action.run(test=opts.test)
70 action.finish(test=opts.test)
72 log.error('Running action "%s.%s" failed: %s', action_name, action_ty, e)
74 log.debug(traceback.format_exc())