I'm trying to deploy a SQL Server VM via ARM template and set backup in the same template.
I've managed to set up the VM and added the VM to backup but not the databases.
I've tried to use some of the quickstart templates on Github, but I don't find any that ascociate the SQL with a backup policy.
I want to enable auto backup on all databases and ascociate a backup policy.
Anyone have any example template?
Auto backup is one of the features of Azure SQL, you don't need to do set it manually, it's automatically.
Configure your backup policy by Change Backup Retention Period between 7 to 35 days.
For Azure SQL Managed instance:
Powershell command:
Set-AzSqlDatabaseBackupShortTermRetentionPolicy -ResourceGroupName resourceGroup -ServerName testserver -DatabaseName testDatabase -RetentionDays 28
REST API:
Sample Request
PUT https://management.azure.com/subscriptions/00000000-1111-2222-3333-444444444444/resourceGroups/resourceGroup/providers/Microsoft.Sql/servers/testserver/databases/testDatabase/backupShortTermRetentionPolicies/default?api-version=2017-10-01-preview
Request Body
{
"properties":{
"retentionDays":28
}
}
Hope this helps.
Related
I created an Azure SQL Database and configured geo-replication to a second server in a different region. In the Azure Portal, I can click on either of the databases, and see details about the regions being replicated to:
I want to use PowerShell to find this same information, but cannot find a cmdlet or property that exposes this information:
# Get database object
$database = Get-AzSqlDatabase -ResourceGroupName test-rg -ServerName testsql-eastus -DatabaseName TestDB
# Find if geo-replication is enabled?
The goal is to be able to pull all SQL databases in a subscription, and take different action on them depending if they have geo-replication enabled.
Please ref these document Get-AzSqlDatabaseFailoverGroup:
Gets a specific Azure SQL Database Failover Group or lists the
Failover Groups on a server. Either server in the Failover Group may
be used to execute the command. The returned values will reflect the
state of the specified server with respect to the Failover Group.
Example:
You can run Get-AzSqlDatabaseFailoverGroup -ResourceGroupName 'rg' -ServerName 'servername' to see if the databases in the Azure SQL server has configured geo-replication. If no failovergroup name return, then the database didn't enable the geo-replication.
I am working on Microsoft Azure, in which I have a group of resources for a test environment and a production environment, in both I have an Azure SQL Databases database server with its respective database.
I am creating a Runbook of Automation Accounts in Powershell in another Microsoft Azure account (Important Note) that is responsible for "Copying" the production database to tests. I know that there is the New-AzSqlDatabaseCopy command, however, this command does not It works with Hyperscale databases.
Is there an alternative to this command in Hyperscale? or in this second account it is possible to create a. Bacpac remotely with Azure commands for Powershell, all I have seen are for working on the same account, but the database account is different from the automation account due to work rates.
Thank you in advance for your help and comments.
I already tried to use the New-AzureRmSqlDatabaseExport command, but it seems to work only in the same Azure Account, and I can't specify "Azure Account for backup" and "Azure account for storage". Am I right?
Like Alberto Morillo says in his comment New-AzSqlDatabaseCopy it's currently not available for Azure SQL HyperScale. at least at the moment of this answer.
So i try to use New-AzureRmSqlDatabaseExport with 2 Azure Accounts and it's tottally possible, you need to login with the Azure Account of the origin database Connect-AzureRmAccount then you need to call the New-AzureRmSqlDatabaseExport command with the following parameters.
New-AzureRmSqlDatabaseExport
-ResourceGroupName $RGName # Resource group of the source database
-ServerName $Server # Server name of the source database
-DatabaseName $Database # Name of the source database
-AdministratorLogin $User # Administrator user of the source database
-AdministratorLoginPassword $Pwd # Password of the source database
-StorageKeytype "StorageAccessKey" # Key type of the destination storage account (The one of the another azure account)
-StorageKey $StorageKey # Key of the destination storage account(The one of the another azure account)
-StorageUri $StorageFileFullURI # The full file uri of the destination storage (The one of the another azure account)
# The format of the URI file is the following:
# https://contosostorageaccount.blob.core.windows.net/backupscontainer/backupdatabasefile.bacpac
unfortunately, this command is not enabled for hyperscale, so I get the following error message:
New-AzureRmSqlDatabaseExport : 40822: This feature is not available for the selected database's edition (Hyperscale).
I used the same command with a database that was not Hyperscale and it worked perfectly.
Finally, I think I will have to perform the manual process for at least a few months, have Microsoft launch the update for HyperScale
Database copy is currently not available for Azure SQL Hyperscale but you may see it in public preview in a few months.
We have a sql server on vm, and a azure sql database, now we want to migrate/restore the vm db to the azure db. I know how to do that via ssms manually. But we want to schedule it because we need to run it daily. I can't find the t-sql scripts to do these. Is there any way?
You can use below PowerShell scripts with Azure Automation to schedule the creation of the bacpac and the import process to Azure SQL Database.
First you need to create a Blob storage account, then create a container on the storage account.
Set-AzureSubscription -CurrentStorageAccountName “YourStorageAccountName” -SubscriptionName $subscription
New-AzureStorageContainer -Name “mycontainer” -Permission Off
Now you need to create a bacpac using SqlPackage. You can schedule the creation of the bacpac using Schedule Tasks on Windows or using PowerShell.
SqlPackage /Action:Export /SourceServerName:SampleSQLServer.sample.net,1433 /SourceDatabaseName:SampleDatabase /TargetFile:"F:\Temp\SampleDatabase.bacpac"
Next upload the bacpac to the storage account using PowerShell.
Set-AzureStorageBlobContent -Container “mycontainer” -File “F:\Temp\SampleDatabase.bacpac”
Now you can import the bacpac to the Azure SQL Database logical server as a new database:
Get-AzureStorageKey –StorageAccountName “YourStorageAccountName”
$primarykey=(Get-AzureStorageKey -StorageAccountName “YourStorageAccountName”).Primary
$StorageUri=(Get-AzureStorageBlob -blob ‘SampleDatabase.bacpac’ -Container ‘mycontainer’).ICloudBlob.uri.AbsoluteUri
In addition to Import/Export you can use Snapshot Replication or Transactional Replication. See Replication to SQL Database single and pooled databases.
You can use SQL Data Sync, it will do several synchronizations per day, you configure the interval yourself.
https://learn.microsoft.com/en-us/azure/sql-database/sql-database-sync-data
Hybrid Data Synchronization: With Data Sync, you can keep data synchronized between your on-premises databases and Azure SQL databases to enable hybrid applications. This capability may appeal to customers who are considering moving to the cloud and would like to put some of their application in Azure.
In TFS I selected Azure VMs File Copy:
My machine is classic and I created classic storage account. I set up the connection using username and password, not management certificate.
The storage account and cloud service I had to populate myself, because they did not appear in the drop-down menu (so possibly something is wrong already at this stage).
In the Cloud Service I entered MyMachine.cloudapp.net.
The task starts, it seems to login successfully, but throws:
Unable to find type [Hyak.Common.CloudException]
Log:
2017-11-24T14:21:28.80333Z Add-AzureAccount -Credential $psCredential
2017-11-24T14:21:35.866333Z Select-AzureSubscription -SubscriptionId -Default
2017-11-24T14:21:35.882333Z Set-AzureSubscription -SubscriptionId yy -CurrentStorageAccountName yyy
2017-11-24T14:21:35.898333Z ##[debug]Starting Azure File Copy Task
2017-11-24T14:21:35.898333Z ##[debug]connectedServiceNameSelector = ConnectedServiceName
2017-11-24T14:21:35.898333Z [debug]connectedServiceName = yyyyyy
(..)
2017-11-24T14:21:35.991333Z ##[debug]Loading AzureUtilityLTE9.8.ps1
2017-11-24T14:21:36.007333Z ##[debug]Connection type used is
UsernamePassword
2017-11-24T14:21:36.022333Z ##[debug]Azure
CallRetrieving storage key for the storage account:
mystorageaccount
2017-11-24T14:21:38.924333Z ##[error]Unable to find type
[Hyak.Common.CloudException].
Please help.
Actually you don't need to manually type the storage account, it will auto appear in the drop list. You just need to specify a pre-existing classic storage account. It is also used as an intermediary for copying files to Azure VMs.
Classic Storage Account
Required if you select Azure Classic for the Azure Connection Type
parameter. The name of an existing storage account within the Azure
subscription.
According to your log, the issue may related to the storage account setting. Double check this configuration under your Azure subscription.
Also suggest you go through this documentation to get more info of the Azure File Copy task. Such as make sure the machine should configured to allow WinRM connections.
One can create a SQL Server on Azure with cmdlet New-AzureSqlDatabaseServer
But how is it possible to set the server name? Azure gave an automatic name, but it is not easy to get it back later
you can set the Azure Sql Server name with https://msdn.microsoft.com/en-us/library/mt163526.aspx
But you will need to change the azure mode to Azure Resource Manager mode with this:
Switch-AzureMode –Name AzureResourceManager
You will also need the latest Azure powershell module here:
http://azure.microsoft.com/en-us/documentation/articles/powershell-install-configure/