private CloudBlobClient GetStorageClient()
        {
            var accountName        = StorageAccountName.Contains(".") ? StorageAccountName.Substring(0, StorageAccountName.IndexOf('.')) : StorageAccountName;
            var storageCredentials = new StorageCredentials(accountName, StorageAccountKey);
            var storageAccount     = new CloudStorageAccount(storageCredentials, true);

            return(storageAccount.CreateCloudBlobClient());
        }
Beispiel #2
0
        public override void ExecuteCmdlet()
        {
            ExecutionBlock(() =>
            {
                base.ExecuteCmdlet();
                StorageAccountName                  = StorageAccountName.ToLower();
                ResourceIdentity identity           = new ResourceIdentity();
                identity.ResourceName               = StorageAccountName;
                identity.ResourceProviderNamespace  = "Microsoft.ClassicStorage/storageAccounts";
                identity.ResourceProviderApiVersion = "2015-12-01";
                identity.ResourceType               = string.Empty;

                ResourcesNS.Models.ResourceGetResult resource = null;
                try
                {
                    WriteDebug(String.Format("Query Microsoft.ClassicStorage with name = {0}",
                                             StorageAccountName));
                    resource = RmClient.Resources.GetAsync(StorageAccountResourceGroupName,
                                                           identity, CancellationToken.None).Result;
                }
                catch (Exception)
                {
                    identity.ResourceProviderNamespace  = "Microsoft.Storage/storageAccounts";
                    identity.ResourceProviderApiVersion = "2016-01-01";
                    resource = RmClient.Resources.GetAsync(StorageAccountResourceGroupName,
                                                           identity, CancellationToken.None).Result;
                }

                string storageAccountId       = resource.Resource.Id;
                string storageAccountlocation = resource.Resource.Location;
                string storageAccountType     = resource.Resource.Type;

                WriteDebug(String.Format("StorageId = {0}", storageAccountId));

                PsBackupProviderManager providerManager = new PsBackupProviderManager(
                    new Dictionary <System.Enum, object>()
                {
                    { RestoreBackupItemParams.RecoveryPoint, RecoveryPoint },
                    { RestoreBackupItemParams.StorageAccountId, storageAccountId },
                    { RestoreBackupItemParams.StorageAccountLocation, storageAccountlocation },
                    { RestoreBackupItemParams.StorageAccountType, storageAccountType }
                }, ServiceClientAdapter);

                IPsBackupProvider psBackupProvider = providerManager.GetProviderInstance(
                    RecoveryPoint.WorkloadType, RecoveryPoint.BackupManagementType);
                var jobResponse = psBackupProvider.TriggerRestore();

                WriteDebug(String.Format("Restore submitted"));
                HandleCreatedJob(jobResponse, Resources.RestoreOperation);
            });
        }
Beispiel #3
0
        private GenericResource GetStorageAccountResource()
        {
            StorageAccountName = StorageAccountName.ToLower();
            ResourceIdentity identity = new ResourceIdentity();

            identity.ResourceName = StorageAccountName;
            identity.ResourceProviderNamespace  = "Microsoft.ClassicStorage/storageAccounts";
            identity.ResourceProviderApiVersion = "2015-12-01";
            identity.ResourceType       = string.Empty;
            identity.ParentResourcePath = string.Empty;

            GenericResource resource = null;

            try
            {
                WriteDebug(string.Format("Query Microsoft.ClassicStorage with name = {0}",
                                         StorageAccountName));
                resource = RmClient.Resources.GetAsync(
                    StorageAccountResourceGroupName,
                    identity.ResourceProviderNamespace,
                    identity.ParentResourcePath,
                    identity.ResourceType,
                    identity.ResourceName,
                    identity.ResourceProviderApiVersion,
                    CancellationToken.None).Result;
            }
            catch (Exception)
            {
                identity.ResourceProviderNamespace  = "Microsoft.Storage/storageAccounts";
                identity.ResourceProviderApiVersion = "2016-01-01";
                resource = RmClient.Resources.GetAsync(
                    StorageAccountResourceGroupName,
                    identity.ResourceProviderNamespace,
                    identity.ParentResourcePath,
                    identity.ResourceType,
                    identity.ResourceName,
                    identity.ResourceProviderApiVersion,
                    CancellationToken.None).Result;
            }

            return(resource);
        }