public async Task BackupAsync(BackupConfiguration configuration, BackupMode mode) { var watch = new Stopwatch(); watch.Start(); configuration.Validate(); var storageFacade = CreateStorageFacade(configuration.StorageAccount); ILogger logger = new StorageFolderLogger(storageFacade.ChangeFolder("logs")); var cosmosFacade = CreateCosmosFacade(configuration.CosmosAccount, logger); var scheduler = new BackupScheduler( logger, cosmosFacade, storageFacade, configuration.GetCollectionPlans(), configuration.Constants); try { await scheduler.InitializeAsync(); try { if (mode == BackupMode.Iterative) { await scheduler.ProcessIterationAsync(); } else { await scheduler.ProcessContinuouslyAsync(); } logger.Display($"Elapsed Time: {watch.Elapsed}"); logger.Display("Memory used: " + $"{Process.GetCurrentProcess().PrivateMemorySize64 / 1024 / 1024} Mb"); } finally { await Task.WhenAll(scheduler.DisposeAsync(), logger.FlushAsync()); } } catch (Exception ex) { logger.DisplayError(ex); } }
public async Task RestoreAsync( RestoreConfiguration configuration, DateTime?pointInTime = null) { var watch = new Stopwatch(); watch.Start(); configuration.Validate(); var storageFacade = CreateStorageFacade(configuration.StorageAccount); ILogger logger = new StorageFolderLogger(storageFacade.ChangeFolder("logs")); var cosmosFacade = CreateCosmosFacade( configuration.CosmosAccount, logger) as ICosmosAccountFacade; var sourceCollectionLogger = logger .AddContext("Db", configuration.SourceCollection.Db) .AddContext("Collection", configuration.SourceCollection.Collection); var indexController = new IndexCollectionController( configuration.SourceCollection.Account, configuration.SourceCollection.Db, configuration.SourceCollection.Collection, storageFacade, null, configuration.Constants.IndexConstants, sourceCollectionLogger); try { await indexController.InitializeAsync(); try { if (pointInTime == null) { await indexController.LoadAsync(true); } else { await indexController.LoadUntilAsync(pointInTime); } var collection = await FindOrCreateCollectionAsync( cosmosFacade, configuration.TargetCollection); var targetCollectionLogger = logger .AddContext("Db", configuration.TargetCollection.Db) .AddContext("Collection", configuration.TargetCollection.Collection); var restoreController = new RestoreController( configuration.SourceCollection.Account, configuration.SourceCollection.Db, configuration.SourceCollection.Collection, storageFacade, collection, targetCollectionLogger); await restoreController.InitializeAsync(); try { await restoreController.RestoreAsync(pointInTime); logger.Display($"Elapsed Time: {watch.Elapsed}"); logger.Display("Memory used: " + $"{Process.GetCurrentProcess().PrivateMemorySize64 / 1024 / 1024} Mb"); } finally { await restoreController.DisposeAsync(); } } finally { await Task.WhenAll(indexController.DisposeAsync(), logger.FlushAsync()); } } catch (Exception ex) { logger.DisplayError(ex); } }