mirror of
https://github.com/YunoHost/yunohost.git
synced 2024-09-03 20:06:10 +02:00
[enh] Review the app backup execution and structure
This commit is contained in:
parent
40ea9a328f
commit
20c4937f81
2 changed files with 27 additions and 9 deletions
|
@ -30,6 +30,7 @@ import json
|
||||||
import errno
|
import errno
|
||||||
import time
|
import time
|
||||||
import tarfile
|
import tarfile
|
||||||
|
import shutil
|
||||||
import subprocess
|
import subprocess
|
||||||
from collections import OrderedDict
|
from collections import OrderedDict
|
||||||
|
|
||||||
|
@ -158,28 +159,44 @@ def backup_create(name=None, description=None, output_directory=None,
|
||||||
# Run apps backup scripts
|
# Run apps backup scripts
|
||||||
tmp_script = '/tmp/backup_' + str(timestamp)
|
tmp_script = '/tmp/backup_' + str(timestamp)
|
||||||
for app_id in apps_filtered:
|
for app_id in apps_filtered:
|
||||||
script = '/etc/yunohost/apps/{:s}/scripts/backup'.format(app_id)
|
app_setting_path = '/etc/yunohost/apps/' + app_id
|
||||||
if not os.path.isfile(script):
|
|
||||||
logger.warning("backup script '%s' not found", script)
|
# Check if the app has a backup script
|
||||||
|
app_script = app_setting_path + '/scripts/backup'
|
||||||
|
if not os.path.isfile(app_script):
|
||||||
|
logger.warning("backup script '%s' not found", app_script)
|
||||||
msignals.display(m18n.n('unbackup_app', app_id),
|
msignals.display(m18n.n('unbackup_app', app_id),
|
||||||
'warning')
|
'warning')
|
||||||
continue
|
continue
|
||||||
|
|
||||||
try:
|
tmp_app_dir = '{:s}/{:s}'.format(tmp_dir, app_id)
|
||||||
msignals.display(m18n.n('backup_running_app_script', app_id))
|
msignals.display(m18n.n('backup_running_app_script', app_id))
|
||||||
subprocess.call(['install', '-Dm555', script, tmp_script])
|
try:
|
||||||
hook_exec(tmp_script, args=[tmp_dir])
|
# Prepare backup directory for the app
|
||||||
|
os.mkdir(tmp_app_dir, 0750)
|
||||||
|
os.mkdir(tmp_app_dir + '/backup', 0750)
|
||||||
|
shutil.copytree(app_setting_path, tmp_app_dir + '/settings')
|
||||||
|
|
||||||
|
# Copy app backup script in a temporary folder and execute it
|
||||||
|
subprocess.call(['install', '-Dm555', app_script, tmp_script])
|
||||||
|
hook_exec(tmp_script, args=[tmp_app_dir + '/backup', app_id])
|
||||||
except:
|
except:
|
||||||
logger.exception("error while executing script '%s'", script)
|
logger.exception("error while executing backup of '%s'", app_id)
|
||||||
msignals.display(m18n.n('unbackup_app', app_id),
|
msignals.display(m18n.n('backup_app_failed', app=app_id),
|
||||||
'error')
|
'error')
|
||||||
|
# Cleaning app backup directory
|
||||||
|
shutil.rmtree(tmp_app_dir, ignore_errors=True)
|
||||||
else:
|
else:
|
||||||
# Add app info
|
# Add app info
|
||||||
i = app_info(app_id)
|
i = app_info(app_id)
|
||||||
info['apps'][app_id] = {
|
info['apps'][app_id] = {
|
||||||
'version': i['version'],
|
'version': i['version'],
|
||||||
}
|
}
|
||||||
subprocess.call(['rm', '-f', tmp_script])
|
finally:
|
||||||
|
try:
|
||||||
|
os.unlink(tmp_script)
|
||||||
|
except OSError:
|
||||||
|
pass
|
||||||
|
|
||||||
# Create backup info file
|
# Create backup info file
|
||||||
with open("%s/info.json" % tmp_dir, 'w') as f:
|
with open("%s/info.json" % tmp_dir, 'w') as f:
|
||||||
|
|
|
@ -150,6 +150,7 @@
|
||||||
"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 named '{:s}'",
|
"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_app_failed" : "Unable to back up the app '{app:s}'",
|
||||||
"backup_complete" : "Backup complete",
|
"backup_complete" : "Backup complete",
|
||||||
"backup_invalid_archive" : "Invalid backup archive",
|
"backup_invalid_archive" : "Invalid backup archive",
|
||||||
"restore_confirm_yunohost_installed" : "Do you really want to restore an already installed system? [{answers:s}]",
|
"restore_confirm_yunohost_installed" : "Do you really want to restore an already installed system? [{answers:s}]",
|
||||||
|
|
Loading…
Add table
Reference in a new issue