[enh] Add a yunohost backup delete command

This commit is contained in:
zamentur 2015-10-02 02:49:04 +02:00
parent b57d945af9
commit 83a796f3ff
3 changed files with 50 additions and 4 deletions

View file

@ -600,7 +600,7 @@ backup:
### backup_restore() ### backup_restore()
restore: restore:
action_help: Restore from a local backup archive action_help: Restore from a local backup archive
api: POST /restore api: POST /backup/restore/<name>
configuration: configuration:
authenticate: false authenticate: false
arguments: arguments:
@ -615,6 +615,9 @@ backup:
--ignore-apps: --ignore-apps:
help: Do not restore apps help: Do not restore apps
action: store_true action: store_true
--ignore-hooks:
help: Do not restore hooks
action: store_true
--force: --force:
help: Force restauration on an already installed system help: Force restauration on an already installed system
action: store_true action: store_true
@ -653,6 +656,18 @@ backup:
help: Print sizes in human readable format help: Print sizes in human readable format
action: store_true action: store_true
### backup_delete()
delete:
action_help: Delete a backup archive
api: DELETE /backup/archives/<name>
configuration:
authenticate: all
arguments:
name:
help: Name of the archive to delete
extra:
pattern: *pattern_backup_archive_name
############################# #############################
# Monitor # # Monitor #

View file

@ -222,7 +222,7 @@ def backup_create(name=None, description=None, output_directory=None,
return { 'archive': info } 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 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) archive_file = '%s/%s.tar.gz' % (archives_path, name)
if not os.path.isfile(archive_file): if not os.path.isfile(archive_file):
logger.error("no local backup archive found at '%s'", 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) info_file = "%s/%s.info.json" % (archives_path, name)
try: try:
@ -412,3 +412,32 @@ def backup_info(name, with_details=False, human_readable=False):
for d in ['apps', 'hooks']: for d in ['apps', 'hooks']:
result[d] = info[d] result[d] = info[d]
return result 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')

View file

@ -147,7 +147,7 @@
"backup_creating_archive" : "Creating the backup archive...", "backup_creating_archive" : "Creating the backup archive...",
"backup_extracting_archive" : "Extracting the backup archive...", "backup_extracting_archive" : "Extracting the backup archive...",
"backup_archive_open_failed" : "Unable to open 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_archive_name_exists" : "Backup archive name already exists",
"backup_complete" : "Backup complete", "backup_complete" : "Backup complete",
"backup_invalid_archive" : "Invalid backup archive", "backup_invalid_archive" : "Invalid backup archive",
@ -157,6 +157,8 @@
"restore_complete" : "Restore complete", "restore_complete" : "Restore complete",
"unbackup_app" : "App '{:s}' will not be saved", "unbackup_app" : "App '{:s}' will not be saved",
"unrestore_app" : "App '{:s}' will not be restored", "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}'", "field_invalid" : "Invalid field '{:s}'",
"mail_domain_unknown" : "Unknown mail address domain '{:s}'", "mail_domain_unknown" : "Unknown mail address domain '{:s}'",