コード例 #1
0
        public async Task <IActionResult> PostRestore([FromBody] RestoreRequestDto request)
        {
            var restoreGrain = grainFactory.GetGrain <IRestoreGrain>(SingleGrain.Id);

            await restoreGrain.RestoreAsync(request.Url, User.Token(), request.Name);

            return(NoContent());
        }
コード例 #2
0
        public async Task <IActionResult> PostRestoreJob([FromBody] RestoreRequestDto request)
        {
            await backupService.StartRestoreAsync(User.Token() !, request.Url, request.Name);

            return(NoContent());
        }
コード例 #3
0
ファイル: BackupTests.cs プロジェクト: vmnet04/squidex
        public async Task Should_backup_and_restore_app()
        {
            var timeout = TimeSpan.FromMinutes(2);

            var appName        = Guid.NewGuid().ToString();
            var appNameRestore = $"{appName}-restore";

            // STEP 1: Create app
            var createRequest = new CreateAppDto {
                Name = appName
            };

            await _.Apps.PostAppAsync(createRequest);


            // STEP 2: Create backup
            await _.Backups.PostBackupAsync(appName);

            BackupJobDto backup = null;

            try
            {
                using (var cts = new CancellationTokenSource(TimeSpan.FromMinutes(2)))
                {
                    while (true)
                    {
                        cts.Token.ThrowIfCancellationRequested();

                        await Task.Delay(1000);

                        var backups = await _.Backups.GetBackupsAsync(appName);

                        if (backups.Items.Count > 0)
                        {
                            backup = backups.Items.FirstOrDefault();

                            break;
                        }
                    }
                }
            }
            catch (OperationCanceledException)
            {
                Assert.True(false, $"Could not retrieve backup within {timeout}.");
            }


            // STEP 3: Restore backup
            var uri = new Uri($"{_.ServerUrl}{backup._links["download"].Href}");

            var restoreRequest = new RestoreRequestDto {
                Url = uri, Name = appNameRestore
            };

            await _.Backups.PostRestoreJobAsync(restoreRequest);

            try
            {
                using (var cts = new CancellationTokenSource(TimeSpan.FromMinutes(2)))
                {
                    while (true)
                    {
                        cts.Token.ThrowIfCancellationRequested();

                        await Task.Delay(1000);

                        var job = await _.Backups.GetRestoreJobAsync();

                        if (job != null && job.Url == uri && job.Status == JobStatus.Completed)
                        {
                            break;
                        }
                    }
                }
            }
            catch (OperationCanceledException)
            {
                Assert.True(false, $"Could not retrieve restored app within {timeout}.");
            }
        }