Example #1
0
        public BackupProgress StartRestore(string backupId, BackupStorageType storageType, Dictionary <string, string> storageParams, bool notify)
        {
            DemandPermissionsRestore();

            var restoreRequest = new StartRestoreRequest
            {
                TenantId = GetCurrentTenantId(),
                NotifyAfterCompletion = notify,
                StorageParams         = storageParams
            };

            Guid guidBackupId;

            if (Guid.TryParse(backupId, out guidBackupId))
            {
                restoreRequest.BackupId = guidBackupId;
            }
            else
            {
                restoreRequest.StorageType  = storageType;
                restoreRequest.FilePathOrId = storageParams["filePath"];

                if (restoreRequest.StorageType == BackupStorageType.Local && !CoreContext.Configuration.Standalone)
                {
                    restoreRequest.FilePathOrId = BackupFileUploadHandler.GetFilePath();
                }
            }

            using (var service = new BackupServiceClient())
            {
                return(service.StartRestore(restoreRequest));
            }
        }
        public BackupProgress StartRestore(StartRestoreRequest request)
        {
            if (request.StorageType == BackupStorageType.Local)
            {
                if (string.IsNullOrEmpty(request.FilePathOrId) || !File.Exists(request.FilePathOrId))
                {
                    throw new FileNotFoundException();
                }
            }

            if (!request.BackupId.Equals(Guid.Empty))
            {
                var backupRepository = BackupStorageFactory.GetBackupRepository();
                var backupRecord     = backupRepository.GetBackupRecord(request.BackupId);
                if (backupRecord == null)
                {
                    throw new FileNotFoundException();
                }

                request.FilePathOrId  = backupRecord.StoragePath;
                request.StorageType   = backupRecord.StorageType;
                request.StorageParams = backupRecord.StorageParams;
            }

            var progress = BackupWorker.StartRestore(request);

            if (!string.IsNullOrEmpty(progress.Error))
            {
                throw new FaultException(progress.Error);
            }
            return(progress);
        }
Example #3
0
        public void StartRestore(StartRestoreRequest request)
        {
            if ((BackupStorageType)request.StorageType == BackupStorageType.Local)
            {
                if (string.IsNullOrEmpty(request.FilePathOrId) || !File.Exists(request.FilePathOrId))
                {
                    throw new FileNotFoundException();
                }
            }

            if (!request.BackupId.Equals(Guid.Empty))
            {
                var backupRecord = BackupRepository.GetBackupRecord(request.BackupId);
                if (backupRecord == null)
                {
                    throw new FileNotFoundException();
                }

                request.FilePathOrId  = backupRecord.StoragePath;
                request.StorageType   = backupRecord.StorageType;
                request.StorageParams = JsonConvert.DeserializeObject <Dictionary <string, string> >(backupRecord.StorageParams);
            }

            var progress = BackupWorker.StartRestore(request);

            if (!string.IsNullOrEmpty(progress.Error))
            {
                throw new FaultException();
            }
        }
        public void StartRestore(string backupId, BackupStorageType storageType, Dictionary <string, string> storageParams, bool notify)
        {
            DemandPermissionsRestore();

            var restoreRequest = new StartRestoreRequest
            {
                TenantId = GetCurrentTenantId(),
                NotifyAfterCompletion = notify,
                StorageParams         = storageParams
            };

            if (Guid.TryParse(backupId, out var guidBackupId))
            {
                restoreRequest.BackupId = guidBackupId;
            }
            else
            {
                restoreRequest.StorageType  = storageType;
                restoreRequest.FilePathOrId = storageParams["filePath"];

                if (restoreRequest.StorageType == BackupStorageType.Local && !CoreBaseSettings.Standalone)
                {
                    restoreRequest.FilePathOrId = BackupFileUploadHandler.GetFilePath();
                }
            }

            BackupService.StartRestore(restoreRequest);
        }
Example #5
0
 public BackupProgress StartRestore(StartRestoreRequest request)
 {
     lock (ProgressQueue.SynchRoot)
     {
         var item = ProgressQueue.GetItems().OfType <RestoreProgressItem>().FirstOrDefault(t => t.TenantId == request.TenantId);
         if (item != null && item.IsCompleted)
         {
             ProgressQueue.Remove(item);
             item = null;
         }
         if (item == null)
         {
             item = FactoryProgressItem.CreateRestoreProgressItem(request, TempFolder, UpgradesPath, CurrentRegion, ConfigPaths);
             ProgressQueue.Add(item);
         }
         return(ToBackupProgress(item));
     }
 }
 public static BackupProgress StartRestore(StartRestoreRequest request)
 {
     lock (tasks.SynchRoot)
     {
         var item = tasks.GetItems().OfType <RestoreProgressItem>().FirstOrDefault(t => t.TenantId == request.TenantId);
         if (item != null && item.IsCompleted)
         {
             tasks.Remove(item);
             item = null;
         }
         if (item == null)
         {
             item = new RestoreProgressItem(request.TenantId, request.StorageType, request.FilePathOrId, request.NotifyAfterCompletion)
             {
                 StorageParams = request.StorageParams
             };
             tasks.Add(item);
         }
         return(ToBackupProgress(item));
     }
 }
        public BackupProgress StartRestore(string backupId, BackupStorageType storageType, StorageParams storageParams, bool notify)
        {
            DemandPermissionsRestore();

            var restoreRequest = new StartRestoreRequest
            {
                TenantId = GetCurrentTenantId(),
                NotifyAfterCompletion = notify
            };

            Guid guidBackupId;

            if (Guid.TryParse(backupId, out guidBackupId))
            {
                restoreRequest.BackupId = guidBackupId;
            }
            else
            {
                restoreRequest.StorageType  = storageType;
                restoreRequest.FilePathOrId = storageParams.FilePath;
                if (storageType == BackupStorageType.CustomCloud)
                {
                    ValidateS3Settings(storageParams.AccessKeyId, storageParams.SecretAccessKey, storageParams.Bucket, storageParams.Region);
                    CoreContext.Configuration.SaveSection(new AmazonS3Settings
                    {
                        AccessKeyId     = storageParams.AccessKeyId,
                        SecretAccessKey = storageParams.SecretAccessKey,
                        Bucket          = storageParams.Bucket,
                        Region          = storageParams.Region
                    });
                }
            }

            using (var service = new BackupServiceClient())
            {
                return(service.StartRestore(restoreRequest));
            }
        }
Example #8
0
        public BackupProgress StartRestore(StartRestoreRequest request)
        {
            if (!request.BackupId.Equals(Guid.Empty))
            {
                var backupRepository = BackupStorageFactory.GetBackupRepository();
                var backupRecord     = backupRepository.GetBackupRecord(request.BackupId);
                if (backupRecord == null)
                {
                    throw new FileNotFoundException();
                }

                request.FilePathOrId = backupRecord.StoragePath;
                request.StorageType  = backupRecord.StorageType;
            }

            var progress = BackupWorker.StartRestore(request.TenantId, request.StorageType, request.FilePathOrId, request.NotifyAfterCompletion);

            if (!string.IsNullOrEmpty(progress.Error))
            {
                throw new FaultException(progress.Error);
            }
            return(progress);
        }