From 83a796f3ff0c23023741cb3ae4ad80d0e35d10bc Mon Sep 17 00:00:00 2001 From: zamentur Date: Fri, 2 Oct 2015 02:49:04 +0200 Subject: [PATCH 1/2] [enh] Add a yunohost backup delete command --- data/actionsmap/yunohost.yml | 17 ++++++++++++++++- lib/yunohost/backup.py | 33 +++++++++++++++++++++++++++++++-- locales/en.json | 4 +++- 3 files changed, 50 insertions(+), 4 deletions(-) diff --git a/data/actionsmap/yunohost.yml b/data/actionsmap/yunohost.yml index ca539090b..29c6a5b6b 100644 --- a/data/actionsmap/yunohost.yml +++ b/data/actionsmap/yunohost.yml @@ -600,7 +600,7 @@ backup: ### backup_restore() restore: action_help: Restore from a local backup archive - api: POST /restore + api: POST /backup/restore/ configuration: authenticate: false arguments: @@ -615,6 +615,9 @@ backup: --ignore-apps: help: Do not restore apps action: store_true + --ignore-hooks: + help: Do not restore hooks + action: store_true --force: help: Force restauration on an already installed system action: store_true @@ -653,6 +656,18 @@ backup: help: Print sizes in human readable format action: store_true + ### backup_delete() + delete: + action_help: Delete a backup archive + api: DELETE /backup/archives/ + configuration: + authenticate: all + arguments: + name: + help: Name of the archive to delete + extra: + pattern: *pattern_backup_archive_name + ############################# # Monitor # diff --git a/lib/yunohost/backup.py b/lib/yunohost/backup.py index 703f4a285..4c0ac2e7b 100644 --- a/lib/yunohost/backup.py +++ b/lib/yunohost/backup.py @@ -222,7 +222,7 @@ def backup_create(name=None, description=None, output_directory=None, return { 'archive': info } -def backup_restore(name, hooks=[], apps=[], ignore_apps=False, force=False): +def backup_restore(name, hooks=[], apps=[], ignore_apps=False, ignore_hooks=False, force=False): """ Restore from a local backup archive @@ -383,7 +383,7 @@ def backup_info(name, with_details=False, human_readable=False): archive_file = '%s/%s.tar.gz' % (archives_path, name) if not os.path.isfile(archive_file): logger.error("no local backup archive found at '%s'", archive_file) - raise MoulinetteError(errno.EIO, m18n.n('backup_archive_name_unknown')) + raise MoulinetteError(errno.EIO, m18n.n('backup_archive_name_unknown',name)) info_file = "%s/%s.info.json" % (archives_path, name) try: @@ -412,3 +412,32 @@ def backup_info(name, with_details=False, human_readable=False): for d in ['apps', 'hooks']: result[d] = info[d] return result + + +def backup_delete(auth, name): + """ + Delete a backup + + Keyword arguments: + name -- Name of the local backup archive + + """ + from yunohost.hook import hook_callback + hook_callback('pre_backup_delete', args=[name]) + + archive_file = '%s/%s.tar.gz' % (archives_path, name) + + info_file = "%s/%s.info.json" % (archives_path, name) + for backup_file in [archive_file,info_file]: + if not os.path.isfile(backup_file): + logger.error("no local backup archive found at '%s'", backup_file) + raise MoulinetteError(errno.EIO, m18n.n('backup_archive_name_unknown', backup_file)) + try: + os.remove(backup_file) + except: + logger.exception("unable to delete '%s'", backup_file) + raise MoulinetteError(errno.EIO, m18n.n('backup_delete_error',backup_file)) + + hook_callback('post_backup_delete', args=[name]) + + msignals.display(m18n.n('backup_deleted'), 'success') diff --git a/locales/en.json b/locales/en.json index 4006ff6ed..85b9b08ed 100644 --- a/locales/en.json +++ b/locales/en.json @@ -147,7 +147,7 @@ "backup_creating_archive" : "Creating the backup archive...", "backup_extracting_archive" : "Extracting the backup archive...", "backup_archive_open_failed" : "Unable to open the backup archive", - "backup_archive_name_unknown" : "Unknown local backup archive name", + "backup_archive_name_unknown" : "Unknown local backup archive named '{:s}'", "backup_archive_name_exists" : "Backup archive name already exists", "backup_complete" : "Backup complete", "backup_invalid_archive" : "Invalid backup archive", @@ -157,6 +157,8 @@ "restore_complete" : "Restore complete", "unbackup_app" : "App '{:s}' will not be saved", "unrestore_app" : "App '{:s}' will not be restored", + "backup_delete_error" : "Unable to delete '{:s}'", + "backup_deleted" : "Backup successfully deleted", "field_invalid" : "Invalid field '{:s}'", "mail_domain_unknown" : "Unknown mail address domain '{:s}'", From 5bb143c32e885e2a079dab18597b2e264eae02e2 Mon Sep 17 00:00:00 2001 From: zamentur Date: Fri, 2 Oct 2015 03:08:11 +0200 Subject: [PATCH 2/2] [fix] Remove --ignore-hooks cause it is unfinished --- data/actionsmap/yunohost.yml | 5 ----- lib/yunohost/backup.py | 4 ++-- 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/data/actionsmap/yunohost.yml b/data/actionsmap/yunohost.yml index 097f68729..a5f0827ba 100644 --- a/data/actionsmap/yunohost.yml +++ b/data/actionsmap/yunohost.yml @@ -617,9 +617,6 @@ backup: --ignore-apps: help: Do not restore apps action: store_true - --ignore-hooks: - help: Do not restore hooks - action: store_true --force: help: Force restauration on an already installed system action: store_true @@ -662,8 +659,6 @@ backup: delete: action_help: Delete a backup archive api: DELETE /backup/archives/ - configuration: - authenticate: all arguments: name: help: Name of the archive to delete diff --git a/lib/yunohost/backup.py b/lib/yunohost/backup.py index 4c0ac2e7b..dfa806e9c 100644 --- a/lib/yunohost/backup.py +++ b/lib/yunohost/backup.py @@ -222,7 +222,7 @@ def backup_create(name=None, description=None, output_directory=None, return { 'archive': info } -def backup_restore(name, hooks=[], apps=[], ignore_apps=False, ignore_hooks=False, force=False): +def backup_restore(name, hooks=[], apps=[], ignore_apps=False, force=False): """ Restore from a local backup archive @@ -414,7 +414,7 @@ def backup_info(name, with_details=False, human_readable=False): return result -def backup_delete(auth, name): +def backup_delete(name): """ Delete a backup