diff --git a/src/ResourceManager/AzureBackup/Commands.AzureBackup/AzureBackUpRestoreBase.cs b/src/ResourceManager/AzureBackup/Commands.AzureBackup/AzureBackUpRestoreBase.cs
new file mode 100644
index 000000000000..cc71cc456c38
--- /dev/null
+++ b/src/ResourceManager/AzureBackup/Commands.AzureBackup/AzureBackUpRestoreBase.cs
@@ -0,0 +1,47 @@
+// ----------------------------------------------------------------------------------
+//
+// Copyright Microsoft Corporation
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+// http://www.apache.org/licenses/LICENSE-2.0
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+// ----------------------------------------------------------------------------------
+
+using System;
+using System.Management.Automation;
+using System.Collections.Generic;
+using System.Xml;
+using Microsoft.WindowsAzure.Commands.Utilities.Common;
+using Microsoft.Azure.Common.Authentication;
+using Microsoft.Azure.Common.Authentication.Models;
+using System.Threading;
+using Hyak.Common;
+using Microsoft.Azure.Commands.AzureBackup.Properties;
+using System.Net;
+using Microsoft.Azure.Commands.AzureBackup.Models;
+using Microsoft.Azure.Commands.AzureBackup.Cmdlets;
+
+namespace Microsoft.Azure.Commands.AzureBackup
+{
+ public abstract class AzureBackupRestoreBase : AzureBackupCmdletBase
+ {
+ // ToDO:
+ // Correct Help message and other attributes related to paameters
+ [Parameter(Position = 0, Mandatory = true, HelpMessage = AzureBackupCmdletHelpMessage.AzureBackUpRecoveryPoint, ValueFromPipeline = true)]
+ [ValidateNotNullOrEmpty]
+ public AzureBackupRecoveryPoint RecoveryPoint { get; set; }
+
+ public override void ExecuteCmdlet()
+ {
+ base.ExecuteCmdlet();
+
+ WriteDebug(String.Format("Cmdlet called for ResourceGroupName: {0}, ResourceName: {1}", RecoveryPoint.ResourceGroupName, RecoveryPoint.ResourceName));
+ InitializeAzureBackupCmdlet(RecoveryPoint.ResourceGroupName, RecoveryPoint.ResourceName);
+ }
+ }
+}
diff --git a/src/ResourceManager/AzureBackup/Commands.AzureBackup/AzureBackupClientAdapter/ItemAdapter.cs b/src/ResourceManager/AzureBackup/Commands.AzureBackup/AzureBackupClientAdapter/ItemAdapter.cs
index 193114bb179b..ba8bc3ce3453 100644
--- a/src/ResourceManager/AzureBackup/Commands.AzureBackup/AzureBackupClientAdapter/ItemAdapter.cs
+++ b/src/ResourceManager/AzureBackup/Commands.AzureBackup/AzureBackupClientAdapter/ItemAdapter.cs
@@ -87,8 +87,9 @@ public Guid EnableProtection(SetProtectionRequestInput request)
///
public Guid TriggerBackup(string containerName, string dsType, string dsId)
{
+ return Guid.NewGuid();
var response = AzureBackupClient.BackUp.TriggerBackUpAsync(GetCustomRequestHeaders(), containerName, dsType, dsId, CmdletCancellationToken).Result;
- return response.OperationId;
+ //return response.OperationId;
}
///
@@ -100,8 +101,9 @@ public Guid TriggerBackup(string containerName, string dsType, string dsId)
///
public IEnumerable ListRecoveryPoints(string containerName, string dsType, string dsId)
{
- var response = AzureBackupClient.RecoveryPoint.ListAsync(GetCustomRequestHeaders(), containerName, dsType, dsId, CmdletCancellationToken).Result;
- return (response != null) ? response.RecoveryPoints.Objects : null;
+ return null;
+ //var response = AzureBackupClient.RecoveryPoint.ListAsync(GetCustomRequestHeaders(), containerName, dsType, dsId, CmdletCancellationToken).Result;
+ //return (response != null) ? response.RecoveryPoints.Objects : null;
}
}
}
\ No newline at end of file
diff --git a/src/ResourceManager/AzureBackup/Commands.AzureBackup/AzureBackupCmdletHelpMessage.cs b/src/ResourceManager/AzureBackup/Commands.AzureBackup/AzureBackupCmdletHelpMessage.cs
index 51c47ac99b89..6ca27732b3b3 100644
--- a/src/ResourceManager/AzureBackup/Commands.AzureBackup/AzureBackupCmdletHelpMessage.cs
+++ b/src/ResourceManager/AzureBackup/Commands.AzureBackup/AzureBackupCmdletHelpMessage.cs
@@ -57,6 +57,8 @@ internal static class AzureBackupCmdletHelpMessage
public const string ProtectionStatus = "Protection Status of the azure backup item.";
public const string AzureBackUpItem = "Azure BackUp Item.";
public const string RecoveryPointId = "Recovery Point Id.";
+ public const string StorageAccountName = "Storage Account Name.";
+ public const string AzureBackUpRecoveryPoint = "Recovery Point.";
public const string Type = "Type of Azure Backup Item.";
public const string Status = "Status of Azure Backup Item";
public const string AzureBackupContainer = "Azure Backup Container for Azure Backup Item.";
diff --git a/src/ResourceManager/AzureBackup/Commands.AzureBackup/Cmdlets/Backup/TriggerBackUp.cs b/src/ResourceManager/AzureBackup/Commands.AzureBackup/Cmdlets/Backup/TriggerBackUp.cs
index 6f567814cc6d..ff58d901123a 100644
--- a/src/ResourceManager/AzureBackup/Commands.AzureBackup/Cmdlets/Backup/TriggerBackUp.cs
+++ b/src/ResourceManager/AzureBackup/Commands.AzureBackup/Cmdlets/Backup/TriggerBackUp.cs
@@ -45,8 +45,8 @@ public override void ExecuteCmdlet()
WriteDebug("Triggered backup. Converting response");
- var operationStatus = TrackOperation(operationId);
- WriteObject(GetCreatedJobs(new Models.AzurePSBackupVault(Item.ResourceGroupName, Item.ResourceName, Item.Location), operationStatus.Jobs).FirstOrDefault());
+ //var operationStatus = TrackOperation(operationId);
+ //WriteObject(GetCreatedJobs(new Models.AzurePSBackupVault(Item.ResourceGroupName, Item.ResourceName, Item.Location), operationStatus.Jobs).FirstOrDefault());
});
}
}
diff --git a/src/ResourceManager/AzureBackup/Commands.AzureBackup/Cmdlets/RecoveryPoint/GetAzureBackupRecoveryPoint.cs b/src/ResourceManager/AzureBackup/Commands.AzureBackup/Cmdlets/RecoveryPoint/GetAzureBackupRecoveryPoint.cs
index e9b48b9c8ac4..86a3c8f93997 100644
--- a/src/ResourceManager/AzureBackup/Commands.AzureBackup/Cmdlets/RecoveryPoint/GetAzureBackupRecoveryPoint.cs
+++ b/src/ResourceManager/AzureBackup/Commands.AzureBackup/Cmdlets/RecoveryPoint/GetAzureBackupRecoveryPoint.cs
@@ -42,30 +42,33 @@ public override void ExecuteCmdlet()
var recoveryPointListResponse = AzureBackupClient.ListRecoveryPoints(Item.ContainerUniqueName, Item.Type, Item.DataSourceId);
- WriteDebug("Received recovery point response");
-
- IEnumerable recoveryPointObjects = null;
- if (Id != null)
+ if (recoveryPointListResponse != null)
{
- RecoveryPointInfo recoveryPointObject = null;
- recoveryPointObjects = recoveryPointListResponse.Where(x => x.InstanceId.Equals(Id, System.StringComparison.InvariantCultureIgnoreCase));
- if (recoveryPointObjects != null && recoveryPointObjects.Any())
+ WriteDebug("Received recovery point response");
+
+ IEnumerable recoveryPointObjects = null;
+ if (Id != null)
{
- WriteDebug("Converting response");
- recoveryPointObject = recoveryPointObjects.FirstOrDefault();
- WriteAzureBackupRecoveryPoint(recoveryPointObject, Item);
+ RecoveryPointInfo recoveryPointObject = null;
+ recoveryPointObjects = recoveryPointListResponse.Where(x => x.InstanceId.Equals(Id, System.StringComparison.InvariantCultureIgnoreCase));
+ if (recoveryPointObjects != null && recoveryPointObjects.Any())
+ {
+ WriteDebug("Converting response");
+ recoveryPointObject = recoveryPointObjects.FirstOrDefault();
+ WriteAzureBackupRecoveryPoint(recoveryPointObject, Item);
+ }
+ else
+ {
+ WriteDebug(string.Format("{0}{1}", "No recovery point exist with Id := ", Id));
+ }
}
else
{
- WriteDebug(string.Format("{0}{1}", "No recovery point exist with Id := ", Id));
+ WriteDebug("Converting response");
+ recoveryPointObjects = recoveryPointListResponse.OrderByDescending(x => x.RecoveryPointTime);
+ WriteAzureBackupRecoveryPoint(recoveryPointObjects, Item);
}
}
- else
- {
- WriteDebug("Converting response");
- recoveryPointObjects = recoveryPointListResponse.OrderByDescending(x => x.RecoveryPointTime);
- WriteAzureBackupRecoveryPoint(recoveryPointObjects, Item);
- }
});
}
diff --git a/src/ResourceManager/AzureBackup/Commands.AzureBackup/Cmdlets/Restore/TriggerRestore.cs b/src/ResourceManager/AzureBackup/Commands.AzureBackup/Cmdlets/Restore/TriggerRestore.cs
new file mode 100644
index 000000000000..2164c64cb75c
--- /dev/null
+++ b/src/ResourceManager/AzureBackup/Commands.AzureBackup/Cmdlets/Restore/TriggerRestore.cs
@@ -0,0 +1,77 @@
+// ----------------------------------------------------------------------------------
+//
+// Copyright Microsoft Corporation
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+// http://www.apache.org/licenses/LICENSE-2.0
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+// ----------------------------------------------------------------------------------
+
+using System;
+using System.Management.Automation;
+using System.Collections.Generic;
+using System.Xml;
+using System.Linq;
+using Microsoft.Azure.Management.BackupServices.Models;
+using MBS = Microsoft.Azure.Management.BackupServices;
+
+namespace Microsoft.Azure.Commands.AzureBackup.Cmdlets
+{
+ ///
+ /// Trigger Restore Job
+ ///
+ [Cmdlet(VerbsData.Restore, "AzureBackupItem"), OutputType(typeof(Guid))]
+ public class RestoreAzureBackup : AzureBackupRestoreBase
+ {
+ [Parameter(Position = 1, Mandatory = true, HelpMessage = AzureBackupCmdletHelpMessage.StorageAccountName)]
+ [ValidateNotNullOrEmpty]
+ public string StorageAccountName { get; set; }
+
+ public override void ExecuteCmdlet()
+ {
+ base.ExecuteCmdlet();
+
+ ExecutionBlock(() =>
+ {
+ WriteVerbose("Making client call");
+ Guid jobId = Guid.NewGuid();
+ WriteDebug("Triggered Restore. Converting response");
+ /*
+ AzureIaaSVMRecoveryInputsCSMObject azureIaaSVMRecoveryInputsCSMObject = new AzureIaaSVMRecoveryInputsCSMObject()
+ {
+ CloudServiceName = string.Empty,
+ VmName = string.Empty,
+ CreateNewCloudService = false,
+ ContinueProtection = false,
+ InputStorageAccountName = StorageAccountName,
+ AffinityGroup = "",
+ Region = RecoveryPoint.Location,
+ };
+
+ JavaScriptSerializer serializer = new JavaScriptSerializer();
+ string azureIaaSVMRecoveryInputsCSMObjectString = serializer.Serialize(azureIaaSVMRecoveryInputsCSMObject);
+
+ CSMRestoreRequest csmRestoreRequest = new CSMRestoreRequest()
+ {
+ Properties = new CSMRestoreRequestProperties()
+ {
+ TypeOfRecovery = RecoveryType.RestoreDisks.ToString(),
+ RecoveryDSTypeSpecificInputs = azureIaaSVMRecoveryInputsCSMObjectString,
+ },
+ };
+
+ Guid operationId = AzureBackupClient.TriggerRestore(RecoveryPoint.ContainerUniqueName, RecoveryPoint.ItemName, RecoveryPoint.RecoveryPointName, csmRestoreRequest);
+ WriteDebug("Triggered Restore. Converting response");
+
+ var operationStatus = TrackOperation(operationId);
+ WriteObject(GetCreatedJobs(new Models.AzurePSBackupVault(RecoveryPoint.ResourceGroupName, RecoveryPoint.ResourceName, RecoveryPoint.Location), operationStatus.Jobs).FirstOrDefault());
+ * */
+ });
+ }
+ }
+}
diff --git a/src/ResourceManager/AzureBackup/Commands.AzureBackup/Commands.AzureBackup.csproj b/src/ResourceManager/AzureBackup/Commands.AzureBackup/Commands.AzureBackup.csproj
index 04d60e2c8c3b..e71ea90a2892 100644
--- a/src/ResourceManager/AzureBackup/Commands.AzureBackup/Commands.AzureBackup.csproj
+++ b/src/ResourceManager/AzureBackup/Commands.AzureBackup/Commands.AzureBackup.csproj
@@ -126,6 +126,7 @@
+
@@ -145,6 +146,7 @@
+