'How to use Backup-SqlDatabase with SAS token?

I'm trying to implement log shipping using Backup-sqldatabase command, but SqlCredential is a required parameter for Azure Storage uploads according to the docs. However, I'm using a Shared Access Token credential, so I can't really use the SqlCredential parameter. If I do, this is the error I get:

Backup-SqlDatabase : System.Data.SqlClient.SqlError: Use of WITH CREDENTIAL syntax is not valid for credentials containing a Shared Access Signature.

Does this mean that SAS tokens/credential can't be used for Backup-sqldatabase?

If I don't include the SqlCredential parameter, I get this error:

Backup-SqlDatabase : System.Data.SqlClient.SqlError: The file name "https://xxxxdev.blob.core.windows.net/DESKTOP-MCxxxx-MSSQL15.MSSQLSERVER-Test123-132767637897201085.bak" is invalid as a backup device name for the specified device type. Reissue the BACKUP statement with a valid file name and device type.

Test123 is just a random test database I created on localhost for testing purposes.



Solution 1:[1]

Looks like SAS token is not supported for Backup-sqldatabase at this time.

The workaround is creating a Maintenance Plan, but that means T-SQL backups no PowerShell.

In this article, you can learn how we can fix the ‘WITH CREDENTIAL syntax is not valid for credentials containing a Shared Access Signature’ error and learn to back up the SQL database to Azure Blob storage using the SQL Server maintenance plan.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 halfer