public static void Run([TimerTrigger("0 0 7 * * *", RunOnStartup = true)] TimerInfo myTimer, ILogger log, ExecutionContext context) { var backupCs = Environment.GetEnvironmentVariable("BackupStorageConnectionString"); var targetCs = Environment.GetEnvironmentVariable("TargetStorageConnectionString"); var backup = new BackupAzureTables(backupCs, targetCs); backup.BackupTableToBlobDirect("characters", "backups", true); backup.BackupTableToBlobDirect("users", "backups", true); }
public void TestBackupToBlobDirectWithCompress() { BackupAzureTables instanceBackup = new BackupAzureTables(AzureStorageConfigConnection, AzureBlobStorageConfigConnection); CopyAzureTables instanceCopy = new CopyAzureTables(AzureStorageConfigConnection); DeleteAzureTables instanceDelete = new DeleteAzureTables(AzureStorageConfigConnection); RestoreAzureTables instanceRestore = new RestoreAzureTables(AzureStorageConfigConnection, AzureBlobStorageConfigConnection); InitializeTables(instanceDelete, instanceRestore, FileNamePathThatExists_SystemLogs); List <Filter> Filters = new List <Filter>(); Filters.Add(new Filter("RowKey", "=", "User1")); Filters.Add(new Filter("RowKey", "=", "User2", "OR")); string copySetup = instanceCopy.CopyTableToTable(TableNameFrom, TableNameTo, 30); int InitialRowCount = ExtractNextInt(copySetup, "total records"); string backupToBlob = instanceBackup.BackupTableToBlobDirect(TableNameFrom, BlobDirectRoot, true, 10, 10); int BackupRowCount = ExtractNextInt(backupToBlob, "total records"); //Need to restore to confirm string restoreResult = instanceRestore.RestoreTableFromBlobDirect(TableNameRestoreTo, TableNameFrom, BlobDirectRoot, ExtractFileName(backupToBlob), 30); string copyVerify = instanceCopy.CopyTableToTable(TableNameRestoreTo, TableNameTo2, 30); int VerifyRowCount = ExtractNextInt(copyVerify, "total records"); Assert.Equal(InitialRowCount, VerifyRowCount); }
public void TestBackupServerNotRunning() { BackupAzureTables bu = new BackupAzureTables(ConnectionSpecNoServer, AzureBlobStorageConfigConnection); Assert.Throws <BackupFailedException>(() => bu.BackupTableToFile(DefaultTableName, WorkingDirectory, false, false, 5)); bu = new BackupAzureTables(AzureStorageConfigConnection, ConnectionSpecNoServer); Assert.Throws <BackupFailedException>(() => bu.BackupTableToBlob(DefaultTableName, DefaultBlobRoot, WorkingDirectory, false, false, 30, 5)); bu = new BackupAzureTables(AzureStorageConfigConnection, ConnectionSpecNoServer); Assert.Throws <BackupFailedException>(() => bu.BackupTableToBlobDirect(DefaultTableName, DefaultBlobRoot, false, 30, 5)); }
public void TestBackupBadConnSpec() { BackupAzureTables bu = new BackupAzureTables(BadConnectionSpec, AzureBlobStorageConfigConnection); Assert.Throws <ConnectionException>(() => bu.BackupTableToFile(DefaultTableName, WorkingDirectory, false, false, 5)); bu = new BackupAzureTables(AzureStorageConfigConnection, BadConnectionSpec); Assert.Throws <ConnectionException>(() => bu.BackupTableToBlob(DefaultTableName, DefaultBlobRoot, WorkingDirectory, false, false, 5, 5)); Assert.Throws <ConnectionException>(() => bu.BackupTableToBlobDirect(DefaultTableName, DefaultBlobRoot, false, 5, 5)); bu = new BackupAzureTables(BadConnectionSpec); Assert.Throws <ConnectionException>(() => bu.BackupTableToBlob(DefaultTableName, DefaultBlobRoot, WorkingDirectory, false, false, 5, 5)); Assert.Throws <ConnectionException>(() => bu.BackupTableToBlobDirect(DefaultTableName, DefaultBlobRoot, false, 5, 5)); }
private string Backup(SecureString AzureBlobStorageConfigConnection, SecureString AzureStorageConfigConnection, IConfiguration config) { try { BackupAzureTables me = new BackupAzureTables(AzureStorageConfigConnection, AzureBlobStorageConfigConnection); string Target = GetFromParmOrFile(config, TargetParmName).ToLower(); if (!String.IsNullOrEmpty(Target)) { var sectionFilters = config.GetSection("Filters"); List <Filter> filters = sectionFilters.Get <List <Filter> >(); if (!Filter.AreFiltersValid(filters)) { throw new Exception("One or more of the supplied filter cirteria is invalid."); } if (Target.Contains("file")) { return(me.BackupTableToFile(GetFromParmOrFile(config, TableNameParmName), GetFromParmOrFile(config, OutFileDirectoryParmName), GetBoolFromParmOrFile(config, CompressParmName), GetBoolFromParmOrFile(config, ValidateParmName), GetIntFromParmOrFile(config, TimeoutSecondsParmName), filters)); } else if (Target.Contains("blobdirect")) { return(me.BackupTableToBlobDirect(GetFromParmOrFile(config, TableNameParmName), GetFromParmOrFile(config, BlobRootParmName), GetBoolFromParmOrFile(config, CompressParmName), GetIntFromParmOrFile(config, RetentionDaysParmName), GetIntFromParmOrFile(config, TimeoutSecondsParmName), filters)); } else if (Target.Contains("blob")) { return(me.BackupTableToBlob(GetFromParmOrFile(config, TableNameParmName), GetFromParmOrFile(config, BlobRootParmName), GetFromParmOrFile(config, OutFileDirectoryParmName), GetBoolFromParmOrFile(config, CompressParmName), GetBoolFromParmOrFile(config, ValidateParmName), GetIntFromParmOrFile(config, RetentionDaysParmName), GetIntFromParmOrFile(config, TimeoutSecondsParmName), filters)); } else { throw new Exception("Missing or invalid configuration for requested command."); } } else { throw new Exception("Missing or invalid configuration for requested command."); } } catch (Exception ex) { throw ex; } }
public void TestBackupParameterExceptions() { BackupAzureTables instanceBackup = new BackupAzureTables(AzureStorageConfigConnection); var exceptionToFileTableMissing = Assert.Throws <ParameterSpecException>(() => instanceBackup.BackupTableToFile("", "baddir")); Assert.True(typeof(ParameterSpecException).IsInstanceOfType(exceptionToFileTableMissing)); Assert.Contains("TableName is missing.", exceptionToFileTableMissing.ToString()); var exceptionToFileOutDirMissing = Assert.Throws <ParameterSpecException>(() => instanceBackup.BackupTableToFile("XX", "")); Assert.True(typeof(ParameterSpecException).IsInstanceOfType(exceptionToFileOutDirMissing)); Assert.Contains("OutFileDirectory is missing.", exceptionToFileOutDirMissing.ToString()); var exceptionToBlobTableMissing = Assert.Throws <ParameterSpecException>(() => instanceBackup.BackupTableToBlob("", "badroot", "baddir")); Assert.True(typeof(ParameterSpecException).IsInstanceOfType(exceptionToBlobTableMissing)); Assert.Contains("TableName is missing.", exceptionToBlobTableMissing.ToString()); var exceptionToBlobBlobRootMissing = Assert.Throws <ParameterSpecException>(() => instanceBackup.BackupTableToBlob("XX", "", "baddir")); Assert.True(typeof(ParameterSpecException).IsInstanceOfType(exceptionToBlobBlobRootMissing)); Assert.Contains("BlobRoot is missing.", exceptionToBlobBlobRootMissing.ToString()); var exceptionToBlobOutDirMissing = Assert.Throws <ParameterSpecException>(() => instanceBackup.BackupTableToBlob("XX", "XX", "")); Assert.True(typeof(ParameterSpecException).IsInstanceOfType(exceptionToBlobOutDirMissing)); Assert.Contains("OutFileDirectory is missing.", exceptionToBlobOutDirMissing.ToString()); var exceptionToBlobDirectTableMissing = Assert.Throws <ParameterSpecException>(() => instanceBackup.BackupTableToBlobDirect("", "badroot")); Assert.True(typeof(ParameterSpecException).IsInstanceOfType(exceptionToBlobDirectTableMissing)); Assert.Contains("TableName is missing.", exceptionToBlobDirectTableMissing.ToString()); var exceptionToBlobDirectBlobRootMissing = Assert.Throws <ParameterSpecException>(() => instanceBackup.BackupTableToBlobDirect("XX", "")); Assert.True(typeof(ParameterSpecException).IsInstanceOfType(exceptionToBlobDirectBlobRootMissing)); Assert.Contains("BlobRoot is missing.", exceptionToBlobDirectBlobRootMissing.ToString()); }