[enh] Add basic 'list' and 'info' actions to the backup

This commit is contained in:
Jérôme Lebleu 2014-11-04 14:11:18 +01:00
parent 82d8b0ac29
commit d1cb0b0d80
4 changed files with 65 additions and 2 deletions

View file

@ -579,6 +579,23 @@ backup:
path:
help: Path of the restauration package
### backup_list()
list:
action_help: List available local backup archives
api: GET /backup/archives
configuration:
lock: false
### backup_info()
info:
action_help: Show info about a local backup archive
api: GET /backup/archives/<name>
configuration:
lock: false
arguments:
name:
help: Name of the local backup archive
#############################
# Monitor #

View file

@ -168,3 +168,45 @@ def backup_restore(path):
msignals.display(m18n.n('restore_complete'), 'success')
def backup_list():
"""
List available local backup archives
"""
result = []
try:
# Retrieve local archives
archives = os.listdir(archives_path)
except IOError as e:
logging.info("unable to iterate over local archives: %s", str(e))
else:
# Iterate over local archives
for f in archives:
try:
name = f[:f.rindex('.tar.gz')]
except ValueError:
continue
result.append(name)
return { 'archives': result }
def backup_info(name):
"""
Get info about a local backup archive
Keyword arguments:
name -- Name of the local backup archive
"""
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'))
return {
'path': archive_file,
# TODO: Retrieve created_at from the info file
'created_at': time.strftime(m18n.n('format_datetime_short'),
time.gmtime(int(name))),
}

View file

@ -131,6 +131,7 @@
"backup_running_hooks" : "Running backup hooks...",
"backup_creating_archive" : "Creating the backup archive...",
"backup_archive_open_failed" : "Unable to open the backup archive",
"backup_archive_name_unknown" : "Unknown local backup archive name",
"backup_complete" : "Backup complete",
"invalid_restore_package" : "Invalid restore package",
"restore_complete" : "Restore complete",
@ -168,6 +169,8 @@
"pattern_password" : "Must be at least 3 characters long",
"pattern_domain" : "Must be a valid domain name (e.g. my-domain.org)",
"pattern_listname" : "Must be alphanumeric and underscore characters only",
"pattern_port" : "Must be a valid port number (i.e. 0-65535)"
"pattern_port" : "Must be a valid port number (i.e. 0-65535)",
"format_datetime_short" : "%m/%d/%Y %I:%M %p"
}

View file

@ -162,6 +162,7 @@
"pattern_password" : "Doit être composé d'au moins 3 caractères",
"pattern_domain" : "Doit être un nom de domaine valide (ex : mon-domaine.org)",
"pattern_listname" : "Doit être composé uniquement de caractères alphanumérique et de tiret bas",
"pattern_port" : "Doit être un numéro de port valide (0-65535)"
"pattern_port" : "Doit être un numéro de port valide (0-65535)",
"format_datetime_short" : "%d/%m/%Y %H:%M"
}