[英]SQL Server backup to URL fails if file exists
I am attempting to backup a database to my Azure Blob storage.我正在尝试将数据库备份到我的 Azure Blob 存储。 The databases are relatively large... between 1 and 30 Gig.
数据库相对较大......在 1 到 30 Gig 之间。
I have successfully backed up the first day, but on subsequent days, I get an error stating that the file already exists and that I need to use the WITH FORMAT.我已经成功备份了第一天,但在随后的几天里,我收到一条错误消息,指出该文件已经存在,我需要使用 WITH FORMAT。
But I need to do a differential backup, as the load of data on a full backup would be very slow and pricey.但是我需要进行差异备份,因为完整备份上的数据负载会非常缓慢且昂贵。
I get the error "MyBackup.bak exists on the remote endpoint, and WITH FORMAT was not specified.".我收到错误“MyBackup.bak 存在于远程端点上,并且未指定 WITH FORMAT。”。
What I am trying to do is:我想做的是:
BACKUP DATABASE [MyDatabase]'
TO URL = 'https://myaccount.blob.core.windows.net/dbbackups/Container/', MyDatabase.bak',
WITH CREDENTIAL = 'AzureDBBackupsContainer'
, DIFFERENTIAL
, COMPRESSION;
I have seen that a differential backup is supported when using URL backups.我已经看到使用 URL 备份时支持差异备份。
Is this actually not possible, or am I doing something wrong?这实际上是不可能的,还是我做错了什么?
It's correct in stopping you, because you need to keep the first full backup.阻止您是正确的,因为您需要保留第一个完整备份。 When you restore your database, you will
当您恢复数据库时,您将
Your script should generate a unique name.您的脚本应该生成一个唯一的名称。 I do this by appending the date and time to the backup filename:
我通过将日期和时间附加到备份文件名来做到这一点:
DECLARE
@now DATETIME,
@datePrefix VARCHAR(MAX),
@timePart VARCHAR(MAX),
@backupFileName VARCHAR(MAX),
@fullUrl VARCHAR(MAX),
@blobServiceEndpoint VARCHAR(MAX)
SET @now = GETDATE();
SET @datePrefix = CONVERT(VARCHAR(8), GETDATE(), 112);
SET @timePart = RIGHT('0' + CONVERT(VARCHAR(2), DATEPART(hh, @now)), 2)
+ RIGHT('0' + CONVERT(VARCHAR(2), DATEPART(mi, @now)), 2)
+ RIGHT('0' + CONVERT(VARCHAR(2), DATEPART(ss, @now)), 2);
SET @backupFileName = 'MyDatabase_' + @datePrefix + @timePart + '.bak';
SET @blobServiceEndpoint = 'https://myaccount.blob.core.windows.net/';
SET @fullUrl = @blobServiceEndpoint + 'Container/' + @backupFileName;
BACKUP DATABASE [MyDatabase]'
TO URL = @fullUrl
WITH CREDENTIAL = 'AzureDBBackupsContainer'
, DIFFERENTIAL
, COMPRESSION;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.