[enh] Restore function

This commit is contained in:
kload 2014-10-25 23:08:03 +02:00
parent a4b5ec6f2d
commit cde48996cf
4 changed files with 50 additions and 0 deletions

View file

@ -562,6 +562,17 @@ backup:
action_help: Create an encrypted backup tarball
api: POST /backup
### backup_restore()
restore:
action_help: Restore from an encrypted backup tarball
api: POST /restore
configuration:
authenticate: false
lock: false
arguments:
path:
help: Path of the restauration package
#############################
# Monitor #

View file

@ -52,3 +52,38 @@ def backup_backup():
#TODO: Compress & encrypt
msignals.display(m18n.n('backup_complete'), 'success')
def backup_restore(path):
"""
Restore from an encrypted backup tarball
Keyword argument:
path -- Path to the restore directory
"""
from yunohost.tools import tools_postinstall
from yunohost.hook import hook_callback
path = os.path.abspath(path)
try:
with open("%s/yunohost/current_host" % path, 'r') as f:
domain = f.readline().rstrip()
except IOError:
raise MoulinetteError(errno.EINVAL, m18n.n('invalid_restore_package'))
#TODO Decrypt & extract tarball
try:
with open('/etc/yunohost/installed') as f:
raise MoulinetteError(errno.EINVAL, m18n.n('yunohost_already_installed'))
except IOError:
tools_postinstall(domain, 'yunohost', True)
# Run hook
hook_callback('restore', [path])
msignals.display(m18n.n('restore_complete'), 'success')

View file

@ -129,6 +129,8 @@
"system_upgraded" : "System successfully upgraded",
"backup_complete" : "Backup complete",
"invalid_restore_package" : "Invalid restore package",
"restore_complete" : "Restore complete",
"field_invalid" : "Invalid field '{:s}'",
"mail_domain_unknown" : "Unknown mail address domain '{:s}'",

View file

@ -129,6 +129,8 @@
"system_upgraded" : "Système mis à jour avec succès",
"backup_complete" : "Sauvegarde terminée",
"invalid_restore_package" : "Dossier de restauration invalide",
"restore_complete" : "Restauration terminée",
"field_invalid" : "Champ incorrect : {:s}",
"mail_domain_unknown" : "Domaine '{:s}' de l'adresse mail inconnu",