mirror of
https://github.com/YunoHost/yunohost.git
synced 2024-09-03 20:06:10 +02:00
Implement migration while restore backup
This commit is contained in:
parent
0d3d33fdce
commit
f22e7144b4
3 changed files with 42 additions and 14 deletions
|
@ -1085,7 +1085,7 @@ backup:
|
||||||
api: POST /backup/restore/<name>
|
api: POST /backup/restore/<name>
|
||||||
configuration:
|
configuration:
|
||||||
authenticate: all
|
authenticate: all
|
||||||
authenticator: ldap-anonymous
|
authenticator: as-root
|
||||||
arguments:
|
arguments:
|
||||||
name:
|
name:
|
||||||
help: Name of the local backup archive
|
help: Name of the local backup archive
|
||||||
|
|
|
@ -800,14 +800,14 @@ class RestoreManager():
|
||||||
|
|
||||||
Public methods:
|
Public methods:
|
||||||
set_targets(self, system_parts=[], apps=[])
|
set_targets(self, system_parts=[], apps=[])
|
||||||
restore(self)
|
restore(self, auth)
|
||||||
|
|
||||||
Usage:
|
Usage:
|
||||||
restore_manager = RestoreManager(name)
|
restore_manager = RestoreManager(name)
|
||||||
|
|
||||||
restore_manager.set_targets(None, ['wordpress__3'])
|
restore_manager.set_targets(None, ['wordpress__3'])
|
||||||
|
|
||||||
restore_manager.restore()
|
restore_manager.restore(auth)
|
||||||
|
|
||||||
if restore_manager.success:
|
if restore_manager.success:
|
||||||
logger.success(m18n.n('restore_complete'))
|
logger.success(m18n.n('restore_complete'))
|
||||||
|
@ -893,6 +893,23 @@ class RestoreManager():
|
||||||
logger.debug("executing the post-install...")
|
logger.debug("executing the post-install...")
|
||||||
tools_postinstall(domain, 'yunohost', True)
|
tools_postinstall(domain, 'yunohost', True)
|
||||||
|
|
||||||
|
def _migrate_system_if_needed(self, auth):
|
||||||
|
"""
|
||||||
|
Do some migration if needed
|
||||||
|
"""
|
||||||
|
|
||||||
|
# Check if we need to do the migration 0009 : setup group and permission
|
||||||
|
result = auth.search('ou=groups,dc=yunohost,dc=org',
|
||||||
|
'(&(objectclass=groupOfNamesYnh)(cn=all_users))',
|
||||||
|
['cn'])
|
||||||
|
if not result:
|
||||||
|
from importlib import import_module
|
||||||
|
migration_0009 = import_module('yunohost.data_migrations.0009_setup_group_permission')
|
||||||
|
# Update LDAP schema restart slapd
|
||||||
|
logger.info(m18n.n("migration_0009_update_LDAP_schema"))
|
||||||
|
service_regen_conf(names=['slapd'], force=True)
|
||||||
|
migration_0009.migrate_LDAP_db(auth)
|
||||||
|
|
||||||
def clean(self):
|
def clean(self):
|
||||||
"""
|
"""
|
||||||
End a restore operations by cleaning the working directory and
|
End a restore operations by cleaning the working directory and
|
||||||
|
@ -1100,7 +1117,7 @@ class RestoreManager():
|
||||||
# "Actual restore" (reverse step of the backup collect part) #
|
# "Actual restore" (reverse step of the backup collect part) #
|
||||||
#
|
#
|
||||||
|
|
||||||
def restore(self):
|
def restore(self, auth):
|
||||||
"""
|
"""
|
||||||
Restore the archive
|
Restore the archive
|
||||||
|
|
||||||
|
@ -1114,8 +1131,9 @@ class RestoreManager():
|
||||||
# Apply dirty patch to redirect php5 file on php7
|
# Apply dirty patch to redirect php5 file on php7
|
||||||
self._patch_backup_csv_file()
|
self._patch_backup_csv_file()
|
||||||
|
|
||||||
self._restore_system()
|
self._restore_system(auth)
|
||||||
self._restore_apps()
|
self._migrate_system_if_needed(auth)
|
||||||
|
self._restore_apps(auth)
|
||||||
finally:
|
finally:
|
||||||
self.clean()
|
self.clean()
|
||||||
|
|
||||||
|
@ -1159,7 +1177,7 @@ class RestoreManager():
|
||||||
logger.warning(m18n.n('backup_php5_to_php7_migration_may_fail',
|
logger.warning(m18n.n('backup_php5_to_php7_migration_may_fail',
|
||||||
error=str(e)))
|
error=str(e)))
|
||||||
|
|
||||||
def _restore_system(self):
|
def _restore_system(self, auth):
|
||||||
""" Restore user and system parts """
|
""" Restore user and system parts """
|
||||||
|
|
||||||
system_targets = self.targets.list("system", exclude=["Skipped"])
|
system_targets = self.targets.list("system", exclude=["Skipped"])
|
||||||
|
@ -1199,15 +1217,15 @@ class RestoreManager():
|
||||||
|
|
||||||
service_regen_conf()
|
service_regen_conf()
|
||||||
|
|
||||||
def _restore_apps(self):
|
def _restore_apps(self, auth):
|
||||||
"""Restore all apps targeted"""
|
"""Restore all apps targeted"""
|
||||||
|
|
||||||
apps_targets = self.targets.list("apps", exclude=["Skipped"])
|
apps_targets = self.targets.list("apps", exclude=["Skipped"])
|
||||||
|
|
||||||
for app in apps_targets:
|
for app in apps_targets:
|
||||||
self._restore_app(app)
|
self._restore_app(auth, app)
|
||||||
|
|
||||||
def _restore_app(self, app_instance_name):
|
def _restore_app(self, auth, app_instance_name):
|
||||||
"""
|
"""
|
||||||
Restore an app
|
Restore an app
|
||||||
|
|
||||||
|
@ -1286,7 +1304,12 @@ class RestoreManager():
|
||||||
filesystem.chown(app_scripts_new_path, 'admin', None, True)
|
filesystem.chown(app_scripts_new_path, 'admin', None, True)
|
||||||
|
|
||||||
# Restore permissions
|
# Restore permissions
|
||||||
|
if os.path.isfile(app_restore_script_in_archive):
|
||||||
os.system("slapadd -l '%s/permission.ldif'" % app_settings_in_archive)
|
os.system("slapadd -l '%s/permission.ldif'" % app_settings_in_archive)
|
||||||
|
else:
|
||||||
|
from importlib import import_module
|
||||||
|
migration_0009 = import_module('yunohost.data_migrations.0009_setup_group_permission')
|
||||||
|
migration_0009.migrate_app_permission(auth, app=app_instance_name)
|
||||||
|
|
||||||
# Copy the app scripts to a writable temporary folder
|
# Copy the app scripts to a writable temporary folder
|
||||||
# FIXME : use 'install -Dm555' or something similar to what's done
|
# FIXME : use 'install -Dm555' or something similar to what's done
|
||||||
|
@ -2137,7 +2160,7 @@ def backup_restore(auth, name, system=[], apps=[], force=False):
|
||||||
#
|
#
|
||||||
|
|
||||||
restore_manager.mount()
|
restore_manager.mount()
|
||||||
restore_manager.restore()
|
restore_manager.restore(auth)
|
||||||
|
|
||||||
# Check if something has been restored
|
# Check if something has been restored
|
||||||
if restore_manager.success:
|
if restore_manager.success:
|
||||||
|
|
|
@ -54,10 +54,15 @@ def migrate_LDAP_db(auth):
|
||||||
user_group_update(auth, 'all_users', add_user=username, force=True, sync_perm=False)
|
user_group_update(auth, 'all_users', add_user=username, force=True, sync_perm=False)
|
||||||
|
|
||||||
|
|
||||||
def migrate_app_permission(auth):
|
def migrate_app_permission(auth, app=None):
|
||||||
logger.info(m18n.n("migration_0009_migrate_permission"))
|
logger.info(m18n.n("migration_0009_migrate_permission"))
|
||||||
|
|
||||||
for app_info in app_list(installed=True)['apps']:
|
if app:
|
||||||
|
apps = app_list(installed=True, filter=app)['apps']
|
||||||
|
else:
|
||||||
|
apps = app_list(installed=True)['apps']
|
||||||
|
|
||||||
|
for app_info in apps:
|
||||||
app = app_info['id']
|
app = app_info['id']
|
||||||
permission = app_setting(app, 'allowed_users')
|
permission = app_setting(app, 'allowed_users')
|
||||||
path = app_setting(app, 'path')
|
path = app_setting(app, 'path')
|
||||||
|
|
Loading…
Add table
Reference in a new issue