简体   繁体   中英

How to schedule daily backup of azure sql managed instance databases to an azure blob

I have a Azure storage account and a blob container. I have 6 databases on my azure sql managed instance. I want to schedule automated daily backup of all the databases to the blob according to a specified CRON expression. How to achieve this. Should I be using some tool or agent or Can it be configured in azure portal?

Azure SQL Managed Instance takes automated backups daily and tran log backup every 5-10 minutes.

If you are looking to backup databases just for peace of mind besides automated backups, the try ola hallengren backup jobs which should work backing up to blob.

https://ola.hallengren.com/sql-server-backup.html

Just remember that if you are using server based TDE, then the copy only backup will not work, you will need to remove the TDE key from database and then backup. Otherwise you can encrypt SQL MI and databases using BYOK from key vault and that will allow you to do backups without issue.

Hopefully this will help

Here are some steps to get it going I would recommend to do the following if you want to do it via T_SQL

1- Create a Blob/Container if doesn't exist.

2- Create a SAS token for the blob. I would recommend using Azure Storage Explorer. It is much easier through that. Also copy the URi for the blob storage

3- Create the credential using T-SQL

https://docs.microsoft.com/en-us/sql/relational-databases/backup-restore/sql-server-backup-to-url?view=sql-server-ver15#credential

Try to do a manual backup first using T-SQL to see if it works. Make sure to change the backup location and dbname

BACKUP DATABASE [<DBname>]
TO URL =  '<https://sqlbackupri.blob.core.windows.net/sqlbackupsmi/Adventureworks1.bak>'
WITH COMPRESSION  
     ,STATS = 5
     ,COPY_ONLY; 
GO

If this works, then download the Maintenance script and run it on a database so all your SP will be in the same database. I would generally create a shell DB like _DBA_Tool

When you are running the script, it will ask if you want to create jobs, you can select yes or no. I would select no since you are looking to create SQL Agent job to do backups

https://ola.hallengren.com/scripts/MaintenanceSolution.sql

Once you run this and it has created SP in the DBA database, you can go ahead and create a SQL Agent job in SSMS and run as this

EXECUTE _DBATools.dbo.DatabaseBackup
@Databases = 'USER_DATABASES',
@URL = '<https://sqlbackupr.blob.core.windows.net/sqlbackupsmi>',
@BackupType = 'FULL',
@Compress = 'Y',
@Verify = 'Y',
@CopyOnly = 'Y'
GO

Just remember, the script will not clean out any backups, you should look into automating cleanup using Azure Automation accounts or Powershell scripts.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM