From 85626134ef30e8af6234a9b40b6c908901bf377e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Lebleu?= Date: Wed, 30 Sep 2015 21:51:28 +0200 Subject: [PATCH] [enh] Allow to filter which app to backup/restore --- data/actionsmap/yunohost.yml | 6 ++++++ lib/yunohost/backup.py | 37 ++++++++++++++++++++++++++++++++---- 2 files changed, 39 insertions(+), 4 deletions(-) diff --git a/data/actionsmap/yunohost.yml b/data/actionsmap/yunohost.yml index ef03afcdb..bbeba80d3 100644 --- a/data/actionsmap/yunohost.yml +++ b/data/actionsmap/yunohost.yml @@ -590,6 +590,9 @@ backup: --hooks: help: List of backup hooks names to execute nargs: "*" + --apps: + help: List of application names to backup + nargs: "*" --ignore-apps: help: Do not backup apps action: store_true @@ -606,6 +609,9 @@ backup: --hooks: help: List of restauration hooks names to execute nargs: "*" + --apps: + help: List of application names to restore + nargs: "*" --ignore-apps: help: Do not restore apps action: store_true diff --git a/lib/yunohost/backup.py b/lib/yunohost/backup.py index 7f98b118d..2e21c3e7d 100644 --- a/lib/yunohost/backup.py +++ b/lib/yunohost/backup.py @@ -42,7 +42,7 @@ logger = getActionLogger('yunohost.backup') def backup_create(name=None, description=None, output_directory=None, - no_compress=False, hooks=[], ignore_apps=False): + no_compress=False, hooks=[], apps=[], ignore_apps=False): """ Create a backup local archive @@ -52,6 +52,7 @@ def backup_create(name=None, description=None, output_directory=None, output_directory -- Output directory for the backup no_compress -- Do not create an archive file hooks -- List of backup hooks names to execute + apps -- List of application names to backup ignore_apps -- Do not backup apps """ @@ -126,8 +127,22 @@ def backup_create(name=None, description=None, output_directory=None, # Add apps backup hook if not ignore_apps: from yunohost.app import app_info + + # Filter applications to backup + apps_list = set(os.listdir('/etc/yunohost/apps')) + apps_filtered = set() + if apps: + for a in apps: + if a not in apps_list: + logger.warning("app '%s' not found", a) + msignals.display(m18n.n('unbackup_app', a), 'warning') + else: + apps_filtered.add(a) + else: + apps_filtered = apps_list + try: - for app_id in os.listdir('/etc/yunohost/apps'): + for app_id in apps_filtered: hook = '/etc/yunohost/apps/%s/scripts/backup' % app_id if os.path.isfile(hook): hook_add(app_id, hook) @@ -192,13 +207,14 @@ def backup_create(name=None, description=None, output_directory=None, msignals.display(m18n.n('backup_complete'), 'success') -def backup_restore(name, hooks=[], ignore_apps=False, force=False): +def backup_restore(name, hooks=[], apps=[], ignore_apps=False, force=False): """ Restore from a local backup archive Keyword argument: name -- Name of the local backup archive hooks -- List of restoration hooks names to execute + apps -- List of application names to restore ignore_apps -- Do not restore apps force -- Force restauration on an already installed system @@ -270,7 +286,20 @@ def backup_restore(name, hooks=[], ignore_apps=False, force=False): # Add apps restore hook if not ignore_apps: - for app_id in info['apps'].keys(): + # Filter applications to restore + apps_list = set(info['apps'].keys()) + apps_filtered = set() + if apps: + for a in apps: + if a not in apps_list: + logger.warning("app '%s' not found", a) + msignals.display(m18n.n('unrestore_app', a), 'warning') + else: + apps_filtered.add(a) + else: + apps_filtered = apps_list + + for app_id in apps_filtered: hook = "/etc/yunohost/apps/%s/scripts/restore" % app_id if os.path.isfile(hook): hook_add(app_id, hook)