mirror of
https://github.com/YunoHost/yunohost.git
synced 2024-09-03 20:06:10 +02:00
[fix] Restore with the app restore script from the backup
This commit is contained in:
parent
98e92bdbac
commit
d83f81be66
7 changed files with 77 additions and 26 deletions
|
@ -628,6 +628,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
|
||||||
|
|
|
@ -1,4 +1,9 @@
|
||||||
backup_dir="$1/conf/ssh"
|
backup_dir="$1/conf/ssh"
|
||||||
|
|
||||||
|
if [ -d /etc/ssh/ ]; then
|
||||||
sudo cp -a $backup_dir/. /etc/ssh
|
sudo cp -a $backup_dir/. /etc/ssh
|
||||||
sudo service ssh restart
|
sudo service ssh restart
|
||||||
|
else
|
||||||
|
echo "SSH is not installed"
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
backup_dir="$1/conf/ynh/mysql"
|
backup_dir="$1/conf/ynh/mysql"
|
||||||
|
|
||||||
service mysql restart
|
sudo service mysql restart
|
||||||
sudo cp -a $backup_dir/mysql /etc/yunohost/mysql
|
sudo cp -a $backup_dir/mysql /etc/yunohost/mysql
|
||||||
mysqlpwd=$(sudo cat /etc/yunohost/mysql)
|
mysqlpwd=$(sudo cat /etc/yunohost/mysql)
|
||||||
sudo mysqladmin flush-privileges -p"$mysqlpwd"
|
sudo mysqladmin flush-privileges -p"$mysqlpwd"
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
backup_dir="$1/conf/ynh/certs"
|
backup_dir="$1/conf/ynh/certs"
|
||||||
|
|
||||||
mkdir -p /etc/yunohost/certs/
|
sudo mkdir -p /etc/yunohost/certs/
|
||||||
|
|
||||||
sudo cp -a $backup_dir/. /etc/yunohost/certs/
|
sudo cp -a $backup_dir/. /etc/yunohost/certs/
|
||||||
sudo yunohost app ssowatconf
|
sudo yunohost app ssowatconf
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
backup_dir="$1/data/mail"
|
backup_dir="$1/data/mail"
|
||||||
|
|
||||||
sudo cp -a $backup_dir/. /var/mail
|
sudo cp -a $backup_dir/. /var/mail/ || echo 'No mail found'
|
||||||
|
|
||||||
# Restart services to use migrated certs
|
# Restart services to use migrated certs
|
||||||
sudo service postfix restart
|
sudo service postfix restart
|
||||||
|
|
|
@ -162,6 +162,8 @@ def backup_create(name=None, description=None, output_directory=None,
|
||||||
for app_id in apps_filtered:
|
for app_id in apps_filtered:
|
||||||
app_setting_path = '/etc/yunohost/apps/' + app_id
|
app_setting_path = '/etc/yunohost/apps/' + app_id
|
||||||
|
|
||||||
|
tmp_app_dir = '{:s}/apps/{:s}'.format(tmp_dir, app_id)
|
||||||
|
|
||||||
# Check if the app has a backup script
|
# Check if the app has a backup script
|
||||||
app_script = app_setting_path + '/scripts/backup'
|
app_script = app_setting_path + '/scripts/backup'
|
||||||
if not os.path.isfile(app_script):
|
if not os.path.isfile(app_script):
|
||||||
|
@ -170,7 +172,21 @@ def backup_create(name=None, description=None, output_directory=None,
|
||||||
'warning')
|
'warning')
|
||||||
continue
|
continue
|
||||||
|
|
||||||
tmp_app_dir = '{:s}/apps/{:s}'.format(tmp_dir, app_id)
|
# Copy the app restore script
|
||||||
|
app_restore_script = app_setting_path + '/scripts/restore'
|
||||||
|
if os.path.isfile(app_script):
|
||||||
|
try:
|
||||||
|
filesystem.mkdir(tmp_app_dir, 0750, True, uid='admin')
|
||||||
|
shutil.copy(app_restore_script, tmp_app_dir)
|
||||||
|
except:
|
||||||
|
logger.exception("error while copying restore script of '%s'", app_id)
|
||||||
|
msignals.display(m18n.n('restore_app_copy_failed', app=app_id),
|
||||||
|
'warning')
|
||||||
|
else:
|
||||||
|
logger.warning("restore script '%s' not found", app_script)
|
||||||
|
msignals.display(m18n.n('unrestorable_app', app_id),
|
||||||
|
'warning')
|
||||||
|
|
||||||
tmp_app_bkp_dir = tmp_app_dir + '/backup'
|
tmp_app_bkp_dir = tmp_app_dir + '/backup'
|
||||||
msignals.display(m18n.n('backup_running_app_script', app_id))
|
msignals.display(m18n.n('backup_running_app_script', app_id))
|
||||||
try:
|
try:
|
||||||
|
@ -251,7 +267,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
|
||||||
|
|
||||||
|
@ -265,6 +281,7 @@ def backup_restore(name, hooks=[], apps=[], ignore_apps=False, force=False):
|
||||||
"""
|
"""
|
||||||
from yunohost.hook import hook_add
|
from yunohost.hook import hook_add
|
||||||
from yunohost.hook import hook_callback
|
from yunohost.hook import hook_callback
|
||||||
|
from yunohost.hook import hook_exec
|
||||||
|
|
||||||
# Retrieve and open the archive
|
# Retrieve and open the archive
|
||||||
archive_file = backup_info(name)['path']
|
archive_file = backup_info(name)['path']
|
||||||
|
@ -329,32 +346,53 @@ def backup_restore(name, hooks=[], apps=[], ignore_apps=False, force=False):
|
||||||
logger.info("executing the post-install...")
|
logger.info("executing the post-install...")
|
||||||
tools_postinstall(domain, 'yunohost', True)
|
tools_postinstall(domain, 'yunohost', True)
|
||||||
|
|
||||||
|
# Run hooks
|
||||||
|
if not ignore_hooks:
|
||||||
|
msignals.display(m18n.n('restore_running_hooks'))
|
||||||
|
hook_callback('restore', hooks, args=[tmp_dir])
|
||||||
|
|
||||||
# Add apps restore hook
|
# Add apps restore hook
|
||||||
if not ignore_apps:
|
if not ignore_apps:
|
||||||
# Filter applications to restore
|
# Filter applications to restore
|
||||||
apps_list = set(info['apps'].keys())
|
apps_list = set(info['apps'].keys())
|
||||||
apps_filtered = set()
|
apps_filtered = set()
|
||||||
if apps:
|
if not apps:
|
||||||
for a in apps:
|
apps=apps_list
|
||||||
if a not in apps_list:
|
|
||||||
logger.warning("app '%s' not found", a)
|
from yunohost.app import _is_installed
|
||||||
msignals.display(m18n.n('unrestore_app', a), 'warning')
|
for app_id in apps:
|
||||||
|
if app_id not in apps_list:
|
||||||
|
logger.warning("app '%s' not found", app_id)
|
||||||
|
msignals.display(m18n.n('unrestore_app', app_id), 'warning')
|
||||||
|
elif _is_installed(app_id):
|
||||||
|
logger.warning("app '%s' already installed", app_id)
|
||||||
|
msignals.display(m18n.n('restore_already_installed_app', app=app_id), 'warning')
|
||||||
|
elif not os.path.isfile('{:s}/apps/{:s}/restore'.format(tmp_dir, app_id)):
|
||||||
|
logger.warning("backup for '%s' doesn't contain a restore script", app_id)
|
||||||
|
msignals.display(m18n.n('no_restore_script', app=app_id), 'warning')
|
||||||
else:
|
else:
|
||||||
apps_filtered.add(a)
|
apps_filtered.add(app_id)
|
||||||
else:
|
|
||||||
apps_filtered = apps_list
|
|
||||||
|
|
||||||
for app_id in apps_filtered:
|
for app_id in apps_filtered:
|
||||||
hook = "/etc/yunohost/apps/%s/scripts/restore" % app_id
|
app_bkp_dir='{:s}/apps/{:s}'.format(tmp_dir, app_id)
|
||||||
if os.path.isfile(hook):
|
try:
|
||||||
hook_add(app_id, hook)
|
# Copy app settings
|
||||||
logger.info("app '%s' will be restored", app_id)
|
app_setting_path = '/etc/yunohost/apps/' + app_id
|
||||||
else:
|
shutil.copytree(app_bkp_dir + '/settings', app_setting_path + '/settings')
|
||||||
msignals.display(m18n.n('unrestore_app', app_id), 'warning')
|
|
||||||
|
# Execute app restore script
|
||||||
|
app_restore_script=app_bkp_dir+'/restore'
|
||||||
|
tmp_script = '/tmp/restore_%s_%s' % (name,app_id)
|
||||||
|
subprocess.call(['install', '-Dm555', app_restore_script, tmp_script])
|
||||||
|
hook_exec(tmp_script, args=[app_bkp_dir, app_id])
|
||||||
|
|
||||||
|
except:
|
||||||
|
logger.exception("error while restoring backup of '%s'", app_id)
|
||||||
|
msignals.display(m18n.n('restore_app_failed', app=app_id),
|
||||||
|
'error')
|
||||||
|
# Cleaning settings directory
|
||||||
|
shutil.rmtree(app_setting_path + '/settings', ignore_errors=True)
|
||||||
|
|
||||||
# Run hooks
|
|
||||||
msignals.display(m18n.n('restore_running_hooks'))
|
|
||||||
hook_callback('restore', hooks, args=[tmp_dir])
|
|
||||||
|
|
||||||
# Remove temporary directory
|
# Remove temporary directory
|
||||||
os.system('rm -rf %s' % tmp_dir)
|
os.system('rm -rf %s' % tmp_dir)
|
||||||
|
|
|
@ -156,10 +156,15 @@
|
||||||
"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}]",
|
||||||
|
"restore_app_failed" : "Unable to restore the app '{app:s}'",
|
||||||
"restore_running_hooks" : "Running restoration hooks...",
|
"restore_running_hooks" : "Running restoration hooks...",
|
||||||
"restore_failed" : "Unable to restore the system",
|
"restore_failed" : "Unable to restore the system",
|
||||||
"restore_complete" : "Restore complete",
|
"restore_complete" : "Restore complete",
|
||||||
|
"restore_already_installed_app": "An app is already installed with the id '{app:s}'",
|
||||||
"unbackup_app" : "App '{:s}' will not be saved",
|
"unbackup_app" : "App '{:s}' will not be saved",
|
||||||
|
"unrestorable_app" : "App '{:s}' will not be restored",
|
||||||
|
"restore_app_copy_failed" : "Unable to copy the restore script of app '{app:s}'",
|
||||||
|
"no_restore_script": "No restore script found for the app '{app:s}'",
|
||||||
"unrestore_app" : "App '{:s}' will not be restored",
|
"unrestore_app" : "App '{:s}' will not be restored",
|
||||||
"backup_delete_error" : "Unable to delete '{:s}'",
|
"backup_delete_error" : "Unable to delete '{:s}'",
|
||||||
"backup_deleted" : "Backup successfully deleted",
|
"backup_deleted" : "Backup successfully deleted",
|
||||||
|
|
Loading…
Add table
Reference in a new issue