简体   繁体   English

如何安排 azure sql 托管实例数据库到 azure blob 的每日备份

[英]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.我有一个 Azure 存储帐户和一个 blob 容器。 I have 6 databases on my azure sql managed instance.我的 azure sql 托管实例上有 6 个数据库。 I want to schedule automated daily backup of all the databases to the blob according to a specified CRON expression.我想根据指定的 CRON 表达式安排所有数据库到 blob 的自动每日备份。 How to achieve this.如何实现这一点。 Should I be using some tool or agent or Can it be configured in azure portal?我应该使用一些工具或代理还是可以在 azure 门户中配置?

Azure SQL Managed Instance takes automated backups daily and tran log backup every 5-10 minutes. Azure SQL 托管实例每天进行自动备份,每 5-10 分钟进行一次日志备份。

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.如果除了自动备份之外,您只是为了安心而希望备份数据库,请尝试 ola hallengren 备份作业,它应该可以备份到 blob。

https://ola.hallengren.com/sql-server-backup.html 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.请记住,如果您使用基于服务器的 TDE,那么仅复制备份将不起作用,您需要从数据库中删除 TDE 密钥,然后进行备份。 Otherwise you can encrypt SQL MI and databases using BYOK from key vault and that will allow you to do backups without issue.否则,您可以使用密钥保管库中的 BYOK 加密 SQL MI 和数据库,这样您就可以毫无问题地进行备份。

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如果您想通过 T_SQL 执行此操作,我建议您执行以下操作

1- Create a Blob/Container if doesn't exist. 1- 如果不存在,则创建一个 Blob/Container。

2- Create a SAS token for the blob. 2- 为 blob 创建一个 SAS 令牌。 I would recommend using Azure Storage Explorer.我建议使用 Azure 存储资源管理器。 It is much easier through that.通过它要容易得多。 Also copy the URi for the blob storage同时复制 blob 存储的 URI

3- Create the credential using T-SQL 3- 使用 T-SQL 创建凭证

https://docs.microsoft.com/en-us/sql/relational-databases/backup-restore/sql-server-backup-to-url?view=sql-server-ver15#credential 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.尝试先使用 T-SQL 进行手动备份,看看它是否有效。 Make sure to change the backup location and dbname确保更改备份位置和 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.如果可行,请下载维护脚本并在数据库上运行它,这样您的所有 SP 都将位于同一个数据库中。 I would generally create a shell DB like _DBA_Tool我通常会创建一个 shell 数据库,例如 _DBA_Tool

When you are running the script, it will ask if you want to create jobs, you can select yes or no.当您运行脚本时,它会询问您是否要创建作业,您可以 select 是或否。 I would select no since you are looking to create SQL Agent job to do backups我会 select 不,因为您正在寻找创建 SQL 代理工作来做备份

https://ola.hallengren.com/scripts/MaintenanceSolution.sql 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一旦你运行它并且它已经在 DBA 数据库中创建了 SP,你可以提前 go 并在 SSMS 中创建一个 SQL 代理作业并像这样运行

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.请记住,该脚本不会清除任何备份,您应该考虑使用 Azure 自动化帐户或 Powershell 脚本进行自动清理。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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