From c97b0588f711ee1f74dab79172e6135c2bc0bec4 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Thu, 27 Oct 2022 15:12:33 +0200 Subject: [PATCH] [Fixes #10195] Backup and restore procedure is not successful (#10196) (#10203) * [Fixes #10195] Backup and restore procedure is not successful * [Fixes #10195] Backup and restore procedure is not successful * [Fixes #10195] Backup and restore procedure is not successful * [Fixes #10195] Backup and restore procedure is not successful * [Fixes #10195] Backup and restore procedure is not successful * [Fixes #10195] test fix build Co-authored-by: mattiagiupponi <51856725+mattiagiupponi@users.noreply.github.com> --- geonode/br/management/commands/backup.py | 24 ++++++------- geonode/br/management/commands/restore.py | 42 +++++++++++++---------- 2 files changed, 36 insertions(+), 30 deletions(-) diff --git a/geonode/br/management/commands/backup.py b/geonode/br/management/commands/backup.py index e36a7895867..1c41c258f16 100644 --- a/geonode/br/management/commands/backup.py +++ b/geonode/br/management/commands/backup.py @@ -189,12 +189,12 @@ def execute_backup(self, **options): for static_files_folder in static_folders: - # skip dumping of static files of apps not located under LOCAL_ROOT path + # skip dumping of static files of apps not located under PROJECT_ROOT path # (check to prevent saving files from site-packages in project-template based GeoNode projects) - if getattr(settings, 'LOCAL_ROOT', None) and \ - not static_files_folder.startswith(settings.LOCAL_ROOT): + if getattr(settings, 'PROJECT_ROOT', None) and \ + not static_files_folder.startswith(settings.PROJECT_ROOT): print(f"Skipping static directory: {static_files_folder}. " - f"It's not located under LOCAL_ROOT path: {settings.LOCAL_ROOT}.") + f"It's not located under PROJECT_ROOT path: {settings.PROJECT_ROOT}.") continue static_folder = os.path.join(static_files_folders, @@ -221,12 +221,12 @@ def execute_backup(self, **options): for template_files_folder in template_folders: - # skip dumping of template files of apps not located under LOCAL_ROOT path + # skip dumping of template files of apps not located under PROJECT_ROOT path # (check to prevent saving files from site-packages in project-template based GeoNode projects) - if getattr(settings, 'LOCAL_ROOT', None) and \ - not template_files_folder.startswith(settings.LOCAL_ROOT): + if getattr(settings, 'PROJECT_ROOT', None) and \ + not template_files_folder.startswith(settings.PROJECT_ROOT): print(f"Skipping template directory: {template_files_folder}. " - f"It's not located under LOCAL_ROOT path: {settings.LOCAL_ROOT}.") + f"It's not located under PROJECT_ROOT path: {settings.PROJECT_ROOT}.") continue template_folder = os.path.join(template_files_folders, @@ -246,12 +246,12 @@ def execute_backup(self, **options): for locale_files_folder in locale_folders: - # skip dumping of locale files of apps not located under LOCAL_ROOT path + # skip dumping of locale files of apps not located under PROJECT_ROOT path # (check to prevent saving files from site-packages in project-template based GeoNode projects) - if getattr(settings, 'LOCAL_ROOT', None) and \ - not locale_files_folder.startswith(settings.LOCAL_ROOT): + if getattr(settings, 'PROJECT_ROOT', None) and \ + not locale_files_folder.startswith(settings.PROJECT_ROOT): logger.info(f"Skipping locale directory: {locale_files_folder}. " - f"It's not located under LOCAL_ROOT path: {settings.LOCAL_ROOT}.") + f"It's not located under PROJECT_ROOT path: {settings.PROJECT_ROOT}.") continue locale_folder = os.path.join(locale_files_folders, diff --git a/geonode/br/management/commands/restore.py b/geonode/br/management/commands/restore.py index 1b501a4eb4d..f146a2f0d9a 100755 --- a/geonode/br/management/commands/restore.py +++ b/geonode/br/management/commands/restore.py @@ -274,14 +274,20 @@ def execute_restore(self, **options): print(f"[Sanity Check] Full Write Access to '{static_root}' ...") chmod_tree(static_root) for static_files_folder in static_folders: - print(f"[Sanity Check] Full Write Access to '{static_files_folder}' ...") - chmod_tree(static_files_folder) + if getattr(settings, 'PROJECT_ROOT', None) and \ + static_files_folder.startswith(settings.PROJECT_ROOT): + print(f"[Sanity Check] Full Write Access to '{static_files_folder}' ...") + chmod_tree(static_files_folder) for template_files_folder in template_folders: - print(f"[Sanity Check] Full Write Access to '{template_files_folder}' ...") - chmod_tree(template_files_folder) + if getattr(settings, 'PROJECT_ROOT', None) and \ + template_files_folder.startswith(settings.PROJECT_ROOT): + print(f"[Sanity Check] Full Write Access to '{template_files_folder}' ...") + chmod_tree(template_files_folder) for locale_files_folder in locale_folders: - print(f"[Sanity Check] Full Write Access to '{locale_files_folder}' ...") - chmod_tree(locale_files_folder) + if getattr(settings, 'PROJECT_ROOT', None) and \ + locale_files_folder.startswith(settings.PROJECT_ROOT): + print(f"[Sanity Check] Full Write Access to '{locale_files_folder}' ...") + chmod_tree(locale_files_folder) except Exception as exception: if notify: restore_notification.apply_async( @@ -400,14 +406,14 @@ def execute_restore(self, **options): # Restore Static Folders for static_files_folder in static_folders: - # skip restoration of static files of apps not located under LOCAL_ROOT path + # skip restoration of static files of apps not located under PROJECT_ROOT path # (check to prevent overriding files from site-packages # in project-template based GeoNode projects) - if getattr(settings, 'LOCAL_ROOT', None) and \ - not static_files_folder.startswith(settings.LOCAL_ROOT): + if getattr(settings, 'PROJECT_ROOT', None) and \ + not static_files_folder.startswith(settings.PROJECT_ROOT): print( f"Skipping static directory: {static_files_folder}. " - f"It's not located under LOCAL_ROOT path: {settings.LOCAL_ROOT}.") + f"It's not located under PROJECT_ROOT path: {settings.PROJECT_ROOT}.") continue if config.gs_data_dt_filter[0] is None: @@ -425,14 +431,14 @@ def execute_restore(self, **options): # Restore Template Folders for template_files_folder in template_folders: - # skip restoration of template files of apps not located under LOCAL_ROOT path + # skip restoration of template files of apps not located under PROJECT_ROOT path # (check to prevent overriding files from site-packages # in project-template based GeoNode projects) - if getattr(settings, 'LOCAL_ROOT', None) and \ - not template_files_folder.startswith(settings.LOCAL_ROOT): + if getattr(settings, 'PROJECT_ROOT', None) and \ + not template_files_folder.startswith(settings.PROJECT_ROOT): print( f"Skipping template directory: {template_files_folder}. " - f"It's not located under LOCAL_ROOT path: {settings.LOCAL_ROOT}.") + f"It's not located under PROJECT_ROOT path: {settings.PROJECT_ROOT}.") continue if config.gs_data_dt_filter[0] is None: @@ -450,14 +456,14 @@ def execute_restore(self, **options): # Restore Locale Folders for locale_files_folder in locale_folders: - # skip restoration of locale files of apps not located under LOCAL_ROOT path + # skip restoration of locale files of apps not located under PROJECT_ROOT path # (check to prevent overriding files from site-packages # in project-template based GeoNode projects) - if getattr(settings, 'LOCAL_ROOT', None) and \ - not locale_files_folder.startswith(settings.LOCAL_ROOT): + if getattr(settings, 'PROJECT_ROOT', None) and \ + not locale_files_folder.startswith(settings.PROJECT_ROOT): print( f"Skipping locale directory: {locale_files_folder}. " - f"It's not located under LOCAL_ROOT path: {settings.LOCAL_ROOT}.") + f"It's not located under PROJECT_ROOT path: {settings.PROJECT_ROOT}.") continue if config.gs_data_dt_filter[0] is None: