Skip to content

Commit a47109a

Browse files
committed
Add missing BackupRestore files from Websites
The BackupRestore folder got missed as the .gitignore file had an exclusion clause for Backup*/
1 parent 945fefe commit a47109a

11 files changed

+729
-0
lines changed
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
// ----------------------------------------------------------------------------------
2+
//
3+
// Copyright Microsoft Corporation
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
// ----------------------------------------------------------------------------------
14+
15+
using System;
16+
using Microsoft.Azure.Management.WebSites.Models;
17+
18+
namespace Microsoft.Azure.Commands.WebApps.Cmdlets.WebApps
19+
{
20+
/// <summary>
21+
/// A simple class containing fields for all metadata associated with a backup.
22+
/// </summary>
23+
public class AzureWebAppBackup
24+
{
25+
/// <summary>
26+
/// The resource group of the web app
27+
/// </summary>
28+
public string ResourceGroupName { get; set; }
29+
30+
/// <summary>
31+
/// The name of the web app
32+
/// </summary>
33+
public string Name { get; set; }
34+
35+
/// <summary>
36+
/// The name of the web app slot
37+
/// </summary>
38+
public string Slot { get; set; }
39+
40+
/// <summary>
41+
/// SAS URL for the storage account container which contains this backup
42+
/// </summary>
43+
public string StorageAccountUrl { get; set; }
44+
45+
/// <summary>
46+
/// Name of the blob which contains data for this backup
47+
/// </summary>
48+
public string BlobName { get; set; }
49+
50+
/// <summary>
51+
/// Databases backed up along with the web app
52+
/// </summary>
53+
public DatabaseBackupSetting[] Databases { get; set; }
54+
55+
/// <summary>
56+
/// The numberic ID of this backup
57+
/// </summary>
58+
public int? BackupId { get; set; }
59+
60+
/// <summary>
61+
/// The user-friendly name of this backup
62+
/// </summary>
63+
public string BackupName { get; set; }
64+
65+
/// <summary>
66+
/// The status of the backup. Possible values are InProgress, Failed, Succeeded,
67+
/// TimedOut, Created, Skipped, PartiallySucceeded, DeleteInProgress, DeleteFailed,
68+
/// Deleted.
69+
/// </summary>
70+
public string BackupStatus { get; set; }
71+
72+
/// <summary>
73+
/// True if this backup was automatically created due to a backup schedule
74+
/// </summary>
75+
public bool? Scheduled { get; set; }
76+
77+
/// <summary>
78+
/// The size of this backup in bytes
79+
/// </summary>
80+
public long? BackupSizeInBytes { get; set; }
81+
82+
/// <summary>
83+
/// Size of the original web app which has been backed up
84+
/// </summary>
85+
public long? WebsiteSizeInBytes { get; set; }
86+
87+
/// <summary>
88+
/// Time when the backup was requested
89+
/// </summary>
90+
public DateTime? Created { get; set; }
91+
92+
/// <summary>
93+
/// Time when the web app was last restored from this backup
94+
/// </summary>
95+
public DateTime? LastRestored { get; set; }
96+
97+
/// <summary>
98+
/// Time when the backup finished
99+
/// </summary>
100+
public DateTime? Finished { get; set; }
101+
102+
/// <summary>
103+
/// Log of any failures or warnings associated with this backup
104+
/// </summary>
105+
public string Log { get; set; }
106+
107+
/// <summary>
108+
/// Unique correlation identifier. Please use this along with the timestamp while communicating with Azure support.
109+
/// </summary>
110+
public string CorrelationId { get; set; }
111+
}
112+
}
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
// ----------------------------------------------------------------------------------
2+
//
3+
// Copyright Microsoft Corporation
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
// ----------------------------------------------------------------------------------
14+
15+
using System;
16+
using Microsoft.Azure.Management.WebSites.Models;
17+
18+
namespace Microsoft.Azure.Commands.WebApps.Cmdlets.WebApps
19+
{
20+
/// <summary>
21+
/// A simple class containing fields for all metadata associated with a backup configuration.
22+
/// </summary>
23+
public class AzureWebAppBackupConfiguration
24+
{
25+
/// <summary>
26+
/// The name of the web app
27+
/// </summary>
28+
public string Name { get; set; }
29+
30+
/// <summary>
31+
/// The resource group of the web app
32+
/// </summary>
33+
public string ResourceGroupName { get; set; }
34+
35+
/// <summary>
36+
/// SAS URL for the storage account container to use for scheduled backups
37+
/// </summary>
38+
public string StorageAccountUrl { get; set; }
39+
40+
/// <summary>
41+
/// Numeric part of backup frequency. For example, for weekly backups, FrequencyInterval = 7 and FrequencyUnit = Day.
42+
/// </summary>
43+
public int? FrequencyInterval { get; set; }
44+
45+
/// <summary>
46+
/// Unit of backup frequency. Valid options are Hour and Day. For example, for weekly backups, FrequencyInterval = 7 and FrequencyUnit = Day.
47+
/// </summary>
48+
public string FrequencyUnit { get; set; }
49+
50+
/// <summary>
51+
/// Number of days the automatic backups should be retained before being automatically deleted.
52+
/// </summary>
53+
public int? RetentionPeriodInDays { get; set; }
54+
55+
/// <summary>
56+
/// The time when the first automatic backup should be created.
57+
/// </summary>
58+
public DateTime? StartTime { get; set; }
59+
60+
/// <summary>
61+
/// The databases to be backed up automatically along with the web app
62+
/// </summary>
63+
public DatabaseBackupSetting[] Databases { get; set; }
64+
65+
/// <summary>
66+
/// True if one backup should always be left in the storage account regardless of retention period.
67+
/// </summary>
68+
public bool? KeepAtLeastOneBackup { get; set; }
69+
70+
/// <summary>
71+
/// True if the automatic backups are enabled.
72+
/// </summary>
73+
public bool? Enabled { get; set; }
74+
}
75+
}
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
// ----------------------------------------------------------------------------------
2+
//
3+
// Copyright Microsoft Corporation
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
// ----------------------------------------------------------------------------------
14+
15+
using System;
16+
using System.Linq;
17+
using Microsoft.Azure.Management.WebSites.Models;
18+
19+
namespace Microsoft.Azure.Commands.WebApps.Cmdlets.WebApps
20+
{
21+
internal class BackupRestoreUtils
22+
{
23+
public static FrequencyUnit StringToFrequencyUnit(string frequencyUnit)
24+
{
25+
FrequencyUnit freq;
26+
try
27+
{
28+
freq = (FrequencyUnit) Enum.Parse(typeof (FrequencyUnit), frequencyUnit, true);
29+
}
30+
catch (ArgumentException)
31+
{
32+
throw new ArgumentException(string.Format("{0} is not a valid FrequencyUnit. Valid options are Hour and Day.", frequencyUnit));
33+
}
34+
return freq;
35+
}
36+
37+
public static AzureWebAppBackup BackupItemToAppBackup(BackupItem backup, string resourceGroupName, string name, string slot)
38+
{
39+
if (backup == null)
40+
{
41+
return new AzureWebAppBackup();
42+
}
43+
var dbs = backup.Databases == null ? null : backup.Databases.ToArray();
44+
string status = backup.Status == null ? null : backup.Status.ToString();
45+
return new AzureWebAppBackup
46+
{
47+
ResourceGroupName = resourceGroupName,
48+
Name = name,
49+
Slot = slot,
50+
StorageAccountUrl = backup.StorageAccountUrl,
51+
BlobName = backup.BlobName,
52+
Databases = dbs,
53+
BackupId = backup.BackupItemId,
54+
BackupName = backup.BackupItemName,
55+
BackupStatus = status,
56+
Scheduled = backup.Scheduled,
57+
BackupSizeInBytes = backup.SizeInBytes,
58+
WebsiteSizeInBytes = backup.WebsiteSizeInBytes,
59+
Created = backup.Created,
60+
LastRestored = backup.LastRestoreTimeStamp,
61+
Finished = backup.FinishedTimeStamp,
62+
Log = backup.Log,
63+
CorrelationId = backup.CorrelationId
64+
};
65+
}
66+
67+
public static AzureWebAppBackupConfiguration BackupRequestToAppBackupConfiguration(BackupRequest configuration, string resourceGroupName, string name, string slot)
68+
{
69+
if (configuration == null)
70+
{
71+
return new AzureWebAppBackupConfiguration();
72+
}
73+
BackupSchedule schedule = configuration.BackupSchedule;
74+
DatabaseBackupSetting[] databases = null;
75+
bool? enabled = configuration.Enabled;
76+
if (configuration.Databases != null)
77+
{
78+
databases = configuration.Databases.ToArray();
79+
}
80+
81+
int? frequencyInterval = null;
82+
string frequencyUnit = null;
83+
int? retentionPeriodInDays = null;
84+
DateTime? startTime = null;
85+
bool? keepAtLeastOneBackup = null;
86+
if (schedule != null)
87+
{
88+
frequencyInterval = schedule.FrequencyInterval;
89+
if (schedule.FrequencyUnit != null)
90+
{
91+
frequencyUnit = schedule.FrequencyUnit.ToString();
92+
}
93+
retentionPeriodInDays = schedule.RetentionPeriodInDays;
94+
startTime = schedule.StartTime;
95+
keepAtLeastOneBackup = schedule.KeepAtLeastOneBackup;
96+
}
97+
98+
return new AzureWebAppBackupConfiguration()
99+
{
100+
Name = name,
101+
ResourceGroupName = resourceGroupName,
102+
StorageAccountUrl = configuration.StorageAccountUrl,
103+
FrequencyInterval = frequencyInterval,
104+
FrequencyUnit = frequencyUnit,
105+
RetentionPeriodInDays = retentionPeriodInDays,
106+
StartTime = startTime,
107+
Databases = databases,
108+
KeepAtLeastOneBackup = keepAtLeastOneBackup,
109+
Enabled = enabled
110+
};
111+
}
112+
}
113+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
// ----------------------------------------------------------------------------------
2+
//
3+
// Copyright Microsoft Corporation
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
// ----------------------------------------------------------------------------------
14+
15+
using System;
16+
using System.Collections.Generic;
17+
using System.Linq;
18+
using System.Management.Automation;
19+
using System.Text;
20+
using System.Threading.Tasks;
21+
using Microsoft.Azure.Commands.WebApps.Cmdlets.BackupRestore;
22+
using Microsoft.Azure.Management.WebSites.Models;
23+
24+
namespace Microsoft.Azure.Commands.WebApps.Cmdlets.WebApps
25+
{
26+
/// <summary>
27+
/// Modifies the automatic backup configuration for an Azure Web App
28+
/// </summary>
29+
[Cmdlet(VerbsData.Edit, "AzureRmWebAppBackupConfiguration"), OutputType(typeof(AzureWebAppBackupConfiguration))]
30+
public class EditAzureWebAppBackupConfiguration : WebAppOptionalSlotBaseCmdlet
31+
{
32+
[Parameter(Position = 3, Mandatory = true, HelpMessage = "The SAS URL for the Azure Storage container used to store the backup.", ValueFromPipelineByPropertyName = true)]
33+
[ValidateNotNullOrEmpty]
34+
public string StorageAccountUrl;
35+
36+
[Parameter(Position = 4, Mandatory = true, HelpMessage = "Numeric value for how often the backups should be made.", ValueFromPipelineByPropertyName = true)]
37+
[ValidateNotNullOrEmpty]
38+
public int FrequencyInterval { get; set; }
39+
40+
[Parameter(Position = 5, Mandatory = true, HelpMessage = "Unit of time for how often the backups should be made. Options are \"Hour\" and \"Day\".", ValueFromPipelineByPropertyName = true)]
41+
[ValidateNotNullOrEmpty]
42+
public string FrequencyUnit { get; set; }
43+
44+
[Parameter(Position = 6, Mandatory = true, HelpMessage = "How many days the automatic backups should be saved before being automatically deleted.", ValueFromPipelineByPropertyName = true)]
45+
[ValidateNotNullOrEmpty]
46+
public int RetentionPeriodInDays { get; set; }
47+
48+
[Parameter(Position = 7, Mandatory = false, HelpMessage = "The time when the automatic backups should begin. Backups will begin immediately if this is null.", ValueFromPipelineByPropertyName = true)]
49+
public DateTime StartTime { get; set; }
50+
51+
[Parameter(Position = 8, Mandatory = false, HelpMessage = "The databases to backup.", ValueFromPipelineByPropertyName = true)]
52+
public DatabaseBackupSetting[] Databases;
53+
54+
[Parameter(Position = 9, Mandatory = false, HelpMessage = "True if one backup should always be kept in the storage account, regardless of how old it is.", ValueFromPipelineByPropertyName = true)]
55+
public SwitchParameter KeepAtLeastOneBackup { get; set; }
56+
57+
public override void ExecuteCmdlet()
58+
{
59+
base.ExecuteCmdlet();
60+
var freq = BackupRestoreUtils.StringToFrequencyUnit(FrequencyUnit);
61+
BackupSchedule schedule = new BackupSchedule(freq, FrequencyInterval, KeepAtLeastOneBackup.IsPresent,
62+
RetentionPeriodInDays, StartTime);
63+
BackupRequest request = new BackupRequest()
64+
{
65+
Location = "",
66+
Enabled = true,
67+
StorageAccountUrl = this.StorageAccountUrl,
68+
BackupSchedule = schedule,
69+
Databases = this.Databases,
70+
BackupRequestType = BackupRestoreOperationType.Default
71+
};
72+
WebsitesClient.UpdateWebAppBackupConfiguration(ResourceGroupName, Name, Slot, request);
73+
var config = new AzureWebAppBackupConfiguration()
74+
{
75+
Name = this.Name,
76+
ResourceGroupName = this.ResourceGroupName,
77+
StorageAccountUrl = this.StorageAccountUrl,
78+
FrequencyInterval = this.FrequencyInterval,
79+
FrequencyUnit = this.FrequencyUnit,
80+
RetentionPeriodInDays = this.RetentionPeriodInDays,
81+
StartTime = this.StartTime,
82+
KeepAtLeastOneBackup = this.KeepAtLeastOneBackup.IsPresent,
83+
Databases = this.Databases,
84+
Enabled = true
85+
};
86+
WriteObject(config);
87+
}
88+
}
89+
}

0 commit comments

Comments
 (0)