Azure Automation (2) periodically delete files from your storage account

Source: Internet
Author: User

Windows Azure Platform Family of articles Catalog

 This article describes the national Azure China by the century connected operation.

This article is a supplement to the author's previous documentation for Azure Backup (1) to back up the database in a SQL Server 2012 virtual machine to azure storage.

I hope that I will first read the introduction to Azure Automation (1) and have a basic understanding of azure Automation.

Demand:

In the previous document, Azure Backup (1) Backs up the database in the SQL Server 2012 virtual machine to Azure Storage,

The author describes using SQL Server job to back up the backup file bak of SQL database to the Azure storage storage account.

But this creates a problem, and as the SQL job runs longer and more times, the database backup file bak grows more and more. How do I set up an Azure Automation scheduled task to remove the old database backup files periodically?

Here the author details about the relevant content.

 The technical details mentioned in this article have several points:

1.Azure ad Account, refer to: Windows Azure Active Directory (3) China Azure ad Add new user

For 2.Azure subscriptions, see: Azure PowerShell (4) managing multiple subscriptions with PowerShell

3.Azure Storage account name, refer to:Windows Azure Storage (1) Windows Azure Storage Service storage Services

4.Azure Storage account container, please refer to:

Azure Storage (2) Windows Azure Storage Service Storage Services blob details (top)

Windows Azure Storage (3) Windows Azure Storage Service Storage Services BLOB details (medium)

Windows Azure Storage (4) Windows Azure Storage Service storage Services blob Share Access Signature

The content of this article is divided into 2 parts:

1. Create a co-admin co-admin

2. Write a runbook that periodically deletes storage accounts

2. Calls to Scheduled Tasks

We start with the first part of the content

1. First we add new users based on previous content,Windows Azure Active Directory (3) China Azure ad , we add a co-admin co-admin

  

The purpose of setting up this co-administrator is that this azure ad account ([email protected]leizha.partner.onmschina.cn) is only used to run Azure Automation and has no other permissions.

  newuser@leizha.partner.onmschina.cn You need to verify your NewUser account and password when running Azure Automation

  

If we set up the service administrator [email protected] to run Azure automation,

The default azure ad password expiration Time is 60 days, if more than 60 days we change the admin account password, will be in the verification of the password error.

So we need a separate Azure AD account to run Azure Automation.

to ensure the readability of the demo, we create a separate Azure AD account [email protected]

2. We create a automation command for leiautomation. Click on the automation, such as:

  

  3. Page jump, we click Runbooks, and then click IMPORT, such as.

  

  

Import the Runbook at the same time. Runbook:Http://files.cnblogs.com/files/threestone/RemoveStorageBlobXDaysOld.rar

  Note that you modify the appropriate parameters before importing , such as the following box:

                #set org ID[Parameter (mandatory=$true)] [String]$AzureOrgId="[Yourazureorgid]",                          #set the password for the org ID[Parameter (Mandatory =$true)] [String]$Password="[Yourazureorgidpassword]",                                #Set subscription name[Parameter (Mandatory =$true)] [String]$AzureSubscriptionName="[Yoursubscriptionname]",                                #set up your storage account[Parameter (Mandatory =$true)] [String]$StorageAccountName="[Yourstorageaccount]",                                #Set Container Name[Parameter (Mandatory =$true)] [String]$ContainerName="[Yourstorageaccountcontainername]",                            #Set Expiration Time[Parameter (Mandatory =$true)] [Int32]$DaysOld=[Xdaysold]

This allows the deletion of old data over xdaysold of a storage account, note that the parameter type of $daysold is Int32, and the assigned parameter does not contain double quotes.

4. After modifying the parameters, we can import the Runbook. Such as:

  

5. Once the import is complete, we can view the Runbook

  

6. Here are some important things to emphasize three times:

The system time for the Azure Automation Runbook is the UTC time zone

The system time for the Azure Automation Runbook is the UTC time zone

The system time for the Azure Automation Runbook is the UTC time zone

The system time for our Automation Runbook is UTC time zone, we need to modify the UTC time zone to utc+8 GMT

$ChinaTimeZone = [System.timezoneinfo]::findsystemtimezonebyid ("China Standard Time")
$Start = [System.timezoneinfo]::converttimefromutc ((get-date). ToUniversalTime (), $ChinaTimeZone)
"Starting:" + $Start. ToString ("HH:mm:ss.ffffzzz")

7. Remember that after importing an azure Automation runbook, you need to publish this Runbook

  

After 8.Publish, we can see the published Runbook project in published

9. After successful execution, we can set up a scheduled task in schedule. We create a new scheduled task, select link to A new Schedule, such as:

  

10. First name this schedule (scheduled Task)

  

  

11. Then set the scheduled task frequency. Such as:

  

We set daily to run once a day, starting at 11 o ' 2015-08-28 a.m.

Here are some important things to emphasize three times:

The system time for the Azure Automation schedule is utc+8 time zone, which is GMT

The system time for Azure Automation schedule is utc+8 time zone , which is Beijing time

The system time for Azure Automation schedule is utc+8 time zone , which is Beijing time

  

  12. Finally set the parameters of this runbook, entries.

  This allows us to design a scheduled task, starting from 2015-08-28 11 o'clock in the morning to execute Azure Automation, once a day, with no expiration time.

This way schedule (scheduled tasks) clears the old data from Azure Storage account every day .

  

Azure Automation (2) periodically delete files from your storage account

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.