private void BackupButton_Click(object sender, RoutedEventArgs e) { this.IsEnabled = false; backupStart = DateTime.Now; Mouse.OverrideCursor = System.Windows.Input.Cursors.Wait; var selectedSources = SourcesView.SelectedItems.Cast <string>().ToArray(); SetStatusText2(""); bool isCancellationRequested() => this.IsClosing; void onCompleted() => Dispatcher.Invoke(() => { backupEnd = DateTime.Now; this.IsEnabled = true; Mouse.OverrideCursor = null; SetStatusText2((backupEnd - backupStart).ToString("G")); StatusLabel1.Content = "Completed."; }); // TODO: Let user choose btw Fastest and Optimal compression level Task.Run(() => backupService.Backup( CompressionLevel.Optimal, selectedSources, Project.Destination, Project.ComplyToGitIgnore, isCancellationRequested, onCompleted, (statusMessage) => SetStatusText1(statusMessage))); }
/// <summary> /// Backup/replicate the data from given snapshot to another storage /// </summary> /// <param name="snapshotId">Snapshot Id to backup</param> /// <param name="storage">Target storage for the backup</param> public void Backup(Guid snapshotId, IKeyValueStorage <Guid, object> storage) { if (storage is ISerializingStorage) { // Inject the serializer ((ISerializingStorage)storage).Serializer = objectSerializationService; } backupService.Backup(snapshotId, provider, new DirectNodeProviderUnsafe <Guid, object, EdgeData>(storage, false)); if (storage is ISerializingStorage) { // Reset the serializer ((ISerializingStorage)storage).Serializer = null; } }
public async Task Execute(string storageKey, string storageSecret, string endpointSuffix = null) { Console.WriteLine(""); Console.WriteLine(this.GetType().FullName); // Export Table using (var storageContext = new StorageContext(storageKey, storageSecret, endpointSuffix)) { using (var textWriter = new StreamWriter("/tmp/test.json")) { await storageContext.ExportToJsonAsync("ExportDemo", textWriter); } } // Export to Blob using (var storageContext = new StorageContext(storageKey, storageSecret, endpointSuffix)) { var backupStorage = new CloudStorageAccount(new StorageCredentials(storageKey, storageSecret), endpointSuffix, true); var backupService = new BackupService(storageContext, backupStorage, new DemoStorageLogger()); await backupService.Backup("DemoBck", "bck01"); } }
private static async Task Main(string[] args) { // Welcome Message Console.WriteLine("Backup Client for Azure Storage Account Tables and Blobs"); Console.WriteLine(""); // Check the global parameters ValidateParameter("SRC_ACCOUNT_NAME"); ValidateParameter("SRC_ACCOUNT_KEY"); ValidateParameter("TGT_ACCOUNT_NAME"); ValidateParameter("TGT_ACCOUNT_KEY"); // Load the global parameters var srcAccountName = Environment.GetEnvironmentVariable("SRC_ACCOUNT_NAME"); var srcAccountKey = Environment.GetEnvironmentVariable("SRC_ACCOUNT_KEY"); var srcAccountEndpointSuffix = Environment.GetEnvironmentVariable("SRC_ACCOUNT_ENDPOINT_SUFFIX"); var tgtAccountName = Environment.GetEnvironmentVariable("TGT_ACCOUNT_NAME"); var tgtAccountKey = Environment.GetEnvironmentVariable("TGT_ACCOUNT_KEY"); var tgtAccountEndpointSuffix = Environment.GetEnvironmentVariable("TGT_ACCOUNT_ENDPOINT_SUFFIX"); // Information Console.WriteLine($" Account Name: {srcAccountName}"); Console.WriteLine($" Account Endpoint-Suffix: {srcAccountEndpointSuffix}"); var storageType = GetStorageTypeOrDefault(); var operationsMode = GetOperationsModeOrDefault(); if (IsTableRestoreMode(storageType, operationsMode)) { // check the local parameters ValidateParameter("SRC_ACCOUNT_CONTAINER"); ValidateParameter("SRC_BACKUP_ID"); // load the local parameters var srcAccountContainer = Environment.GetEnvironmentVariable("SRC_ACCOUNT_CONTAINER"); var srcBackupId = Environment.GetEnvironmentVariable("SRC_BACKUP_ID"); // log Console.WriteLine($" Storage Type: Table"); Console.WriteLine($" Operations Mode: Restore"); // instantiate the logger var logger = new BackupStorageLogger(); // build a storage context using (var storageContext = new StorageContext(tgtAccountName, tgtAccountKey, tgtAccountEndpointSuffix)) { // build the cloud account var backupStorageAccount = new CloudStorageAccount(new StorageCredentials(srcAccountName, srcAccountKey), srcAccountEndpointSuffix, true); // instantiate the backup service var backupService = new BackupService(storageContext, backupStorageAccount, logger); // exceute the backup await backupService.Restore(srcAccountContainer, srcBackupId).ConfigureAwait(false); } // Thank you Console.WriteLine("Restore is finished"); } else if (IsTableBackupMode(storageType, operationsMode)) { // check the local parameters ValidateParameter("TGT_ACCOUNT_CONTAINER"); // load the local parameters var tgtAccountContainer = Environment.GetEnvironmentVariable("TGT_ACCOUNT_CONTAINER"); var srcExcludeTables = Environment.GetEnvironmentVariable("SRC_EXCLUDE_TABLES"); // process exclude tables var excludeTablesList = new List <string>(); if (!string.IsNullOrEmpty(srcExcludeTables)) { excludeTablesList = new List <string>(srcExcludeTables.Split(',')); } PrintExcludedStorage(excludeTablesList, tables: true); // log Console.WriteLine($" Storage Type: Table"); Console.WriteLine($" Operations Mode: Backup"); // instantiate the logger var logger = new BackupStorageLogger(); // build a storage context using (var storageContext = new StorageContext(srcAccountName, srcAccountKey, srcAccountEndpointSuffix)) { // build the cloud account var backupStorageAccount = new CloudStorageAccount(new StorageCredentials(tgtAccountName, tgtAccountKey), tgtAccountEndpointSuffix, true); // instantiate the backup service var backupService = new BackupService(storageContext, backupStorageAccount, logger); // build the backup prefix var prefix = DateTime.UtcNow.ToString("yyyy-MM-dd") + "-" + Guid.NewGuid().ToString(); // log Console.WriteLine($" Backup Prefix: {prefix}"); // exceute the backup await backupService.Backup(tgtAccountContainer, prefix, excludeTablesList.ToArray()).ConfigureAwait(false); } // Thank you Console.WriteLine("Backup is finished"); } else if (IsBlobRestoreMode(storageType, operationsMode)) { // check the local parameters ValidateParameter("SRC_ACCOUNT_CONTAINER"); ValidateParameter("SRC_BACKUP_ID"); // load the local parameters var srcAccountContainer = Environment.GetEnvironmentVariable("SRC_ACCOUNT_CONTAINER"); var srcBackupId = Environment.GetEnvironmentVariable("SRC_BACKUP_ID"); // load option parameters int parallelOperationThreadCount = GetParallelOperationThreadCountVariable(); long singleBlobUploadThresholdInBytes = GetSingleBlobUploadThresholdInBytesVariable(); bool areBlobsCompressed = GetBlobCompressionVariable(); // log Console.WriteLine($" Storage Type: Blob"); Console.WriteLine($" Operations Mode: Restore"); // instantiate the logger var logger = new BackupStorageLogger(); var srcBlobStorageAccount = new CloudStorageAccount(new StorageCredentials(srcAccountName, srcAccountKey), srcAccountEndpointSuffix, true); var tgtBlobStorageAccount = new CloudStorageAccount(new StorageCredentials(tgtAccountName, tgtAccountKey), tgtAccountEndpointSuffix, true); var blobRequestOptions = new BlobRequestOptions { ParallelOperationThreadCount = parallelOperationThreadCount, // 10 simultanously uploaded blocks SingleBlobUploadThresholdInBytes = singleBlobUploadThresholdInBytes // block size of 32 MB is default }; Console.WriteLine($" ParallelOperationThreadCount: {parallelOperationThreadCount}"); Console.WriteLine($" SingleBlobUploadThresholdInBytes: {singleBlobUploadThresholdInBytes}"); // blob service var backupService = new BlobService(srcBlobStorageAccount, tgtBlobStorageAccount, blobRequestOptions, logger); // execute the restore await backupService.Restore(srcAccountContainer, srcBackupId, areBlobsCompressed).ConfigureAwait(false); } else if (IsBlobBackupMode(storageType, operationsMode)) { // check the local parameters ValidateParameter("TGT_ACCOUNT_CONTAINER"); int parallelOperationThreadCount = GetParallelOperationThreadCountVariable(); long singleBlobUploadThresholdInBytes = GetSingleBlobUploadThresholdInBytesVariable(); bool compressBlobs = GetBlobCompressionVariable(); // load the local parameters var tgtAccountContainer = Environment.GetEnvironmentVariable("TGT_ACCOUNT_CONTAINER"); var srcExcludedBlobContainers = Environment.GetEnvironmentVariable("SRC_EXCLUDE_BLOB_CONTAINER"); // process exclude tables var excludedBlobContainers = new List <string>(); if (!string.IsNullOrEmpty(srcExcludedBlobContainers)) { excludedBlobContainers = new List <string>(srcExcludedBlobContainers.Split(',')); } PrintExcludedStorage(excludedBlobContainers, tables: false); // log Console.WriteLine($" Storage Type: Blob"); Console.WriteLine($" Operations Mode: Backup"); // instantiate the logger var logger = new BackupStorageLogger(); var srcBlobStorageAccount = new CloudStorageAccount(new StorageCredentials(srcAccountName, srcAccountKey), srcAccountEndpointSuffix, true); var tgtBlobStorageAccount = new CloudStorageAccount(new StorageCredentials(tgtAccountName, tgtAccountKey), tgtAccountEndpointSuffix, true); var blobRequestOptions = new BlobRequestOptions { ParallelOperationThreadCount = parallelOperationThreadCount, // 10 simultanously uploaded blocks SingleBlobUploadThresholdInBytes = singleBlobUploadThresholdInBytes // block size of 32 MB is default }; Console.WriteLine($" ParallelOperationThreadCount: {parallelOperationThreadCount}"); Console.WriteLine($" SingleBlobUploadThresholdInBytes: {singleBlobUploadThresholdInBytes}"); // blob service var backupService = new BlobService(srcBlobStorageAccount, tgtBlobStorageAccount, blobRequestOptions, logger); // build the backup prefix var virtualFilePath = DateTime.UtcNow.ToString("yyyy-MM-dd") + "-" + Guid.NewGuid().ToString(); // execute the backup await backupService.Backup(tgtAccountContainer, virtualFilePath, excludedBlobContainers, compressBlobs).ConfigureAwait(false); } else { Console.WriteLine("Storage type and operations mode invalid."); } }