public static void Main(string[] args)
        {
            string hostName = string.Concat("Newest-Host-", Guid.NewGuid().ToString());

            if (string.IsNullOrEmpty(ConfigurationManager.AppSettings["ModeOfOperation"]))
            {
                Console.WriteLine("Mode of operation [Backup/Restore] must be specified in configuration file. Please retry after setting mode of operation.");
            }
            else if (ConfigurationManager.AppSettings["ModeOfOperation"].Equals("Backup"))
            {
                string monitoredUri       = ConfigurationManager.AppSettings["CosmosDBEndpointUri"];
                string monitoredSecretKey = ConfigurationManager.AppSettings["CosmosDBAuthKey"];

                DocumentClient client = CreateDocumentClient(monitoredUri, monitoredSecretKey);

                BackupExecutor backupExecutor = new BackupExecutor(client, hostName);
                backupExecutor.ExecuteBackup().Wait();
            }
            else if (ConfigurationManager.AppSettings["ModeOfOperation"].Equals("Restore"))
            {
                string restoreAccountUri       = ConfigurationManager.AppSettings["RestoreAccountUri"];
                string restoreAccountSecretKey = ConfigurationManager.AppSettings["RestoreAccountSecretKey"];

                DocumentClient client = CreateDocumentClient(restoreAccountUri, restoreAccountSecretKey);

                RestoreExecutor restoreExecutor = new RestoreExecutor(client, hostName);
                restoreExecutor.ExecuteRestore().Wait();
            }

            Console.WriteLine("Completed!");
            Console.ReadLine();
        }
Exemplo n.º 2
0
        public void TestBackupsToBlobStorageAccount()
        {
            string hostName = string.Concat("Host-", Guid.NewGuid().ToString());

            var tasks = new List <Task>();

            // 1. Trigger the data generator to insert sample documents into the test collection
            IDataGenerator dataGenerator = new EmployeeSampleDataGenerator(this.client);

            tasks.Add(Task.Factory.StartNew(() =>
            {
                dataGenerator.GenerateSampleData().Wait();
            }));

            // 2. Trigger the backup executor to fetch all changes to the source collection and backup the changes to the specified Blob Storage Account
            BackupExecutor backupExecutor = new BackupExecutor(client, hostName);

            backupExecutor.ExecuteBackup().Wait();

            // 3. Wait for both (1) DataGenerator and (2) BackupExecutor to finish execution
            Task.WaitAll(tasks.ToArray());
            Thread.Sleep(60 * 2 * 1000);

            //// 4. Validate the number of documents backed up to Blob Storage
            int numberOfSampleDocumentsGenerated = int.Parse(ConfigurationManager.AppSettings["NumDocumentsToGenerate"]);

            Console.WriteLine("Count retrieved = {0}", BlobStorageHelper.GetListOfDocumentsBackedUpInContainer(this.CloudBlobClient));
            Assert.AreEqual(BlobStorageHelper.GetListOfDocumentsBackedUpInContainer(this.CloudBlobClient), numberOfSampleDocumentsGenerated);
        }
Exemplo n.º 3
0
        public void TestRestoreToBlobStorageAccount()
        {
            string hostName = string.Concat("Host-", Guid.NewGuid().ToString());

            string         restoreAccountName       = ConfigurationManager.AppSettings["RestoreAccountUri"];
            string         restoreAccountKey        = ConfigurationManager.AppSettings["RestoreAccountSecretKey"];
            DocumentClient documentClientForRestore = Utilities.CreateDocumentClient(restoreAccountName, restoreAccountKey);

            var tasks = new List <Task>();

            // 1. Trigger the data generator to insert sample documents into the test collection
            IDataGenerator dataGenerator = new EmployeeSampleDataGenerator(documentClientForRestore);

            tasks.Add(Task.Factory.StartNew(() =>
            {
                dataGenerator.GenerateSampleData().Wait();
            }));

            // 2. Trigger the backup executor to fetch all changes to the source collection and backup the changes to the specified Blob Storage Account
            BackupExecutor backupExecutor = new BackupExecutor(client, hostName);

            backupExecutor.ExecuteBackup().Wait();

            // 3. Wait for both (1) DataGenerator and (2) BackupExecutor to finish execution
            Task.WaitAll(tasks.ToArray());
            Thread.Sleep(60 * 2 * 1000);

            // 4. Validate the number of documents backed up to Blob Storage
            int numberOfSampleDocumentsGenerated = int.Parse(ConfigurationManager.AppSettings["NumDocumentsToGenerate"]);

            Assert.AreEqual(BlobStorageHelper.GetListOfDocumentsBackedUpInContainer(this.CloudBlobClient), numberOfSampleDocumentsGenerated);

            tasks = new List <Task>();

            RestoreExecutor restoreExecutor = new RestoreExecutor(client, hostName);

            tasks.Add(Task.Factory.StartNew(() =>
            {
                restoreExecutor.ExecuteRestore().Wait();
            }));

            Task.WaitAll(tasks.ToArray());

            string monitoredDatabaseName   = ConfigurationManager.AppSettings["DatabaseName"];
            string monitoredCollectionName = ConfigurationManager.AppSettings["CollectionName"];

            string restoreDatabaseName   = ConfigurationManager.AppSettings["RestoreDatabaseName"];
            string restoreCollectionName = ConfigurationManager.AppSettings["RestoreCollectionName"];

            long documentCountInSourceCollection   = CosmosDBHelper.FetchDocumentCountInCollection(this.client, monitoredDatabaseName, monitoredCollectionName).Result;
            long documentCountInRestoredCollection = CosmosDBHelper.FetchDocumentCountInCollection(documentClientForRestore, restoreDatabaseName, restoreCollectionName).Result;

            Assert.AreEqual(documentCountInSourceCollection, documentCountInRestoredCollection);
        }