コード例 #1
0
        internal async Task <string> RestoreClone(SnapSession session)
        {
            try
            {
                session.HostName = session.CloneHostName;
                log.Info($"restoring clone with session: {session.toString()}");
                session.DbKey = await this.GetDbKey(session, false);

                log.Info($"DB Key of the clone received: {session.DbKey}");
                // Got Junction Path : This parameter is needed for Restore API Call
                session.JunctionPath = await this.GetJunctionPath(session, false);

                log.Info($"JunctionPath of the clone received: {session.JunctionPath}");



                PrimaryBackup b = new PrimaryBackup();
                b.BackupName = session.BackupName;
                RestoreBody          body         = new RestoreBody();
                RestoreConfiguration cloneConfApp = new RestoreConfiguration();
                cloneConfApp.type = "SMCoreContracts.SmSCRestoreConfiguration, SMCoreContracts";
                //Extra Parameters needed in Restore Body:-
                cloneConfApp.MountCommands = new System.Collections.Generic.List <string>();
                cloneConfApp.MountCommands.Add($"mount {session.LeafIP}:{session.JunctionPath} {session.MountPath} ; sleep 3; /var/lib/start-mysql.sh");

                cloneConfApp.UnMountCommands = new System.Collections.Generic.List <string>();
                cloneConfApp.UnMountCommands.Add($"killall -KILL mysqld ; sleep 3 ; umount {session.MountPath}");

                Backups back = new Backups();
                back.PrimaryBackup     = b;
                body.BackupInfo        = back;
                body.PluginCode        = "SCC";
                body.RestoreLastBackup = 0;
                body.Configuration     = cloneConfApp;

                var response = await this.SendRequestAsync <dynamic>(Method.POST, $"api/3.0/plugins/{session.Plugin}/resources/{session.DbKey}/restore", body, false);

                return(response.Response.StatusCode.ToString());
            }
            catch (Exception ex)
            {
                this.log.Error($"Error while cloning {session.DbKey}: {ex}");
                throw;
            }
        }
コード例 #2
0
        private static async Task RestoreAsync(Container sourceContainer, Container targetContainer)
        {
            var metaController       = new MetaController();
            var restoreConfiguration = new RestoreConfiguration
            {
                CosmosAccount    = CosmosCollectionRental.CosmosConfiguration,
                StorageAccount   = Storage.StorageConfiguration,
                SourceCollection = new CompleteCollectionConfiguration
                {
                    Account    = CosmosCollectionRental.CosmosConfiguration.Name,
                    Db         = CosmosCollectionRental.DatabaseName,
                    Collection = sourceContainer.Id,
                },
                TargetCollection = new CollectionConfiguration
                {
                    Db         = CosmosCollectionRental.DatabaseName,
                    Collection = targetContainer.Id
                }
            };

            await metaController.RestoreAsync(restoreConfiguration);
        }
コード例 #3
0
        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);
            }
        }