[enh] Allow to ignore backup hooks execution at creation

This commit is contained in:
Jérôme Lebleu 2015-10-02 03:40:06 +02:00
parent 1daae564ae
commit 999a61d2b2
3 changed files with 16 additions and 6 deletions

View file

@ -594,6 +594,9 @@ backup:
--hooks: --hooks:
help: List of backup hooks names to execute help: List of backup hooks names to execute
nargs: "*" nargs: "*"
--ignore-hooks:
help: Do not execute backup hooks
action: store_true
--apps: --apps:
help: List of application names to backup help: List of application names to backup
nargs: "*" nargs: "*"

View file

@ -43,7 +43,8 @@ logger = getActionLogger('yunohost.backup')
def backup_create(name=None, description=None, output_directory=None, def backup_create(name=None, description=None, output_directory=None,
no_compress=False, hooks=[], apps=[], ignore_apps=False): no_compress=False, ignore_hooks=False, hooks=[],
ignore_apps=False, apps=[]):
""" """
Create a backup local archive Create a backup local archive
@ -53,6 +54,7 @@ def backup_create(name=None, description=None, output_directory=None,
output_directory -- Output directory for the backup output_directory -- Output directory for the backup
no_compress -- Do not create an archive file no_compress -- Do not create an archive file
hooks -- List of backup hooks names to execute hooks -- List of backup hooks names to execute
ignore_hooks -- Do not execute backup hooks
apps -- List of application names to backup apps -- List of application names to backup
ignore_apps -- Do not backup apps ignore_apps -- Do not backup apps
@ -62,6 +64,11 @@ def backup_create(name=None, description=None, output_directory=None,
tmp_dir = None tmp_dir = None
# Validate what to backup
if ignore_hooks and ignore_apps:
raise MoulinetteError(errno.EINVAL,
m18n.n('backup_action_required'))
# Validate and define backup name # Validate and define backup name
timestamp = int(time.time()) timestamp = int(time.time())
if not name: if not name:
@ -126,11 +133,10 @@ def backup_create(name=None, description=None, output_directory=None,
} }
# Run system hooks # Run system hooks
msignals.display(m18n.n('backup_running_hooks')) if not ignore_hooks:
hooks_ret = hook_callback('backup', hooks, args=[tmp_dir]) msignals.display(m18n.n('backup_running_hooks'))
hooks_ret = hook_callback('backup', hooks, args=[tmp_dir])
# Add hooks results to the info info['hooks'] = hooks_ret['succeed']
info['hooks'] = hooks_ret['succeed']
# Backup apps # Backup apps
if not ignore_apps: if not ignore_apps:

View file

@ -139,6 +139,7 @@
"packages_upgrade_failed" : "Unable to upgrade all packages", "packages_upgrade_failed" : "Unable to upgrade all packages",
"system_upgraded" : "System successfully upgraded", "system_upgraded" : "System successfully upgraded",
"backup_action_required" : "You must specify something to backup",
"backup_output_directory_required" : "You must provide an output directory for the backup", "backup_output_directory_required" : "You must provide an output directory for the backup",
"backup_output_directory_forbidden" : "Forbidden output directory", "backup_output_directory_forbidden" : "Forbidden output directory",
"backup_output_directory_not_empty" : "Output directory is not empty", "backup_output_directory_not_empty" : "Output directory is not empty",