From 814d4169b3d8c2b00189a2bf577928de3cd54364 Mon Sep 17 00:00:00 2001 From: Jorrit Boekel Date: Thu, 28 Nov 2024 15:40:36 +0100 Subject: [PATCH] Restoring from backup is done to the primary servershare, not the accidental no-longer-existing one --- src/backend/datasets/jobs.py | 8 ++++++-- src/backend/jobs/views.py | 3 ++- src/backend/rawstatus/jobs.py | 2 +- src/backend/rawstatus/tasks.py | 3 ++- 4 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/backend/datasets/jobs.py b/src/backend/datasets/jobs.py index 93b58243..fe3e0c04 100644 --- a/src/backend/datasets/jobs.py +++ b/src/backend/datasets/jobs.py @@ -317,10 +317,14 @@ class ReactivateDeletedDataset(DatasetJob): task = filetasks.pdc_restore def process(self, **kwargs): - for sfile in self.getfiles_query(**kwargs).exclude(mzmlfile__isnull=False).filter(purged=True, pdcbackedupfile__isnull=False): + for sfile in self.getfiles_query(**kwargs).exclude(mzmlfile__isnull=False).filter( + purged=True, pdcbackedupfile__isnull=False): self.run_tasks.append((rsjobs.restore_file_pdc_runtask(sfile), {})) # Also set archived/archivable files which are already active (purged=False) to not deleted in UI - self.getfiles_query(**kwargs).filter(purged=False, deleted=True, pdcbackedupfile__isnull=False).update(deleted=False) + self.getfiles_query(**kwargs).filter(purged=False, deleted=True, pdcbackedupfile__isnull=False + ).update(deleted=False) + Dataset.objects.filter(kwargs['dset_id']).update( + storageshare=ServerShare.objects.get(name=settings.PRIMARY_STORAGESHARENAME)) class DeleteDatasetPDCBackup(DatasetJob): diff --git a/src/backend/jobs/views.py b/src/backend/jobs/views.py index 914f3206..46504840 100644 --- a/src/backend/jobs/views.py +++ b/src/backend/jobs/views.py @@ -292,7 +292,8 @@ def restored_archive_file(request): data['client_id'], [settings.STORAGECLIENT_APIKEY]): return HttpResponseForbidden() sfile = StoredFile.objects.filter(pk=data['sfid']) - sfile.update(deleted=False, purged=False) + sfile.update(deleted=False, purged=False, + servershare_id=ServerShare.objects.get(name=data['serversharename']) if 'task' in request.POST: set_task_done(request.POST['task']) return HttpResponse() diff --git a/src/backend/rawstatus/jobs.py b/src/backend/rawstatus/jobs.py index ee98bd97..c736955b 100644 --- a/src/backend/rawstatus/jobs.py +++ b/src/backend/rawstatus/jobs.py @@ -268,7 +268,7 @@ def restore_file_pdc_runtask(sfile): backupfile = models.PDCBackedupFile.objects.get(storedfile=sfile) fnpath = os.path.join(sfile.path, sfile.filename) yearmonth = datetime.strftime(sfile.regdate, '%Y%m') - return (sfile.servershare.name, fnpath, backupfile.pdcpath, sfile.id, backupfile.is_dir) + return (settings.PRIMARY_STORAGESHARENAME, fnpath, backupfile.pdcpath, sfile.id, backupfile.is_dir) def call_proteomexchange(pxacc): diff --git a/src/backend/rawstatus/tasks.py b/src/backend/rawstatus/tasks.py index 8bcfea2d..167f6935 100644 --- a/src/backend/rawstatus/tasks.py +++ b/src/backend/rawstatus/tasks.py @@ -380,7 +380,8 @@ def pdc_restore(self, servershare, filepath, pdcpath, fn_id, isdir): except Exception: taskfail_update_db(self.request.id, msg='File {} to retrieve from backup is directory ' 'type, it is retrieved to {} but errored when moving from there'.format(fileloc, pdcpath)) - postdata = {'sfid': fn_id, 'task': self.request.id, 'client_id': settings.APIKEY} + postdata = {'sfid': fn_id, 'task': self.request.id, 'client_id': settings.APIKEY, + 'serversharename': servershare} url = urljoin(settings.KANTELEHOST, reverse('jobs:restoredpdcarchive')) msg = ('Restore from archive could not update database with for fn {} with PDC path {} :' '{}'.format(filepath, pdcpath, '{}'))