You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airavata.apache.org by ma...@apache.org on 2023/04/18 17:05:41 UTC
[airavata-django-portal] 02/13: AIRAVATA-3694 Basic unarchive_user_data command
This is an automated email from the ASF dual-hosted git repository.
machristie pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/airavata-django-portal.git
commit b9dc12e4e27e4f7ef199b36590736ffb399b8f81
Author: Marcus Christie <ma...@apache.org>
AuthorDate: Mon Apr 17 15:48:26 2023 -0400
AIRAVATA-3694 Basic unarchive_user_data command
---
.../admin/management/commands/archive_user_data.py | 2 +-
.../management/commands/unarchive_user_data.py | 28 ++++++++++++++++++++++
2 files changed, 29 insertions(+), 1 deletion(-)
diff --git a/django_airavata/apps/admin/management/commands/archive_user_data.py b/django_airavata/apps/admin/management/commands/archive_user_data.py
index 0d45e931..4eae0904 100644
--- a/django_airavata/apps/admin/management/commands/archive_user_data.py
+++ b/django_airavata/apps/admin/management/commands/archive_user_data.py
@@ -68,7 +68,7 @@ class Command(BaseCommand):
with transaction.atomic():
user_data_archive = models.UserDataArchive(
archive_name=archive_tarball_filename,
- archive_path=os.fspath(archive_directory / archive_list_filename),
+ archive_path=os.fspath(archive_directory / archive_tarball_filename),
max_modification_time=max_age)
user_data_archive.save()
# delete archived entries
diff --git a/django_airavata/apps/admin/management/commands/unarchive_user_data.py b/django_airavata/apps/admin/management/commands/unarchive_user_data.py
new file mode 100644
index 00000000..d1d817d0
--- /dev/null
+++ b/django_airavata/apps/admin/management/commands/unarchive_user_data.py
@@ -0,0 +1,28 @@
+
+import os
+import tarfile
+
+from django.core.management.base import BaseCommand
+
+from django_airavata.apps.admin import models
+
+
+class Command(BaseCommand):
+ help = "Unarchive a user data archive"
+
+ def add_arguments(self, parser):
+ parser.add_argument('archive_file',
+ help="Archive file (ending in .tgz) that was created by the archive_user_data")
+
+ def handle(self, *args, **options):
+ with tarfile.open(options["archive_file"]) as tf:
+ tf.extractall(path="/")
+
+ # mark archive as rolled back
+ archive_name = os.path.basename(options["archive_file"])
+ try:
+ archive = models.UserDataArchive.objects.get(archive_name=archive_name)
+ archive.rolled_back = True
+ archive.save()
+ except models.UserDataArchive.DoesNotExist:
+ self.stdout.write(self.style.ERROR(f"Could not find UserDataArchive database record for {archive_name}"))