question

ErinDavis-3903 avatar image
0 Votes"
ErinDavis-3903 asked ·

Azure Blob download using PowerShell

We receive weekly FULL and daily DIFF back ups from our hosted ERP quoting system provider. We are using PowerShell code and task scheduler to download the most recent file from a blob container to a local server location we use for our back ups. Once downloaded we have a SQL restore job that uses those downloaded files.

When I download the files from Azure Storage explorer manually and run the restore job it works fine. When I run the restore job from the Powershell downloaded file i get an error.

.bak' is incorrectly formed and can not be read.

Or the code will work perfectly for a week and then stop downloading properly. I receive that same error or it just gets sutck.

I cannot figure out why this is happening. Anyone run into this and fix it?

Is there a better way to get the files to download automatically and then restore? We need to always pull the most recent file for the week.

14711-powershell.jpg


sql-server-generalazure-blob-storage
powershell.jpg (148.9 KiB)
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Sumarigo-MSFT avatar image
0 Votes"
Sumarigo-MSFT answered ·

@ErinDavis-3903 Firstly, apologies for the delay in responding here and any inconvenience this issue may have caused.

For better understanding the issue : Are you using the same blob in task scheduler and PowerShell?

  • Are you using the differential backup instead of a full backup?

  • Can you share the screen shot of the error message?

  • Which version SQL Server are using?
    -

Additional information: This error may also arise if the SQL Backup Agent service doesn't have the necessary permissions. For example, if you are restoring across a network, the SQL Backup Agent service must have read permission to access the folder containing the backups. For more information on the permissions required by the SQL Backup Agent service, check Permissions once


(If the reply was helpful please don't forget to accept as answer, thank you)

· 3 ·
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

@ErinDavis-3903 Just checking in if you have had a chance to see the previous response. We need the previously asked information to understand/investigate this issue further.

1 Vote 1 ·

We are using task scheduler to run the PowerShell code for the blob. We use it to download the latest differential and/or full.. We are using PowerShell 7 for the code. We have code for the differential each day and then one for the full on Sunday.

SQL Server is 2017.

We download the back up from the blob container to a network drive and then run SQL to restore.

When I download manually we never have an issue with the restore script.

When we use the PowerShell it will run fine for a while and the restore will work but sometimes it will either finish the download and I get the attached error when I try to restore, or it will just get stuck and not finish.

0 Votes 0 ·

I put a reply in the wrong spot I think. Sorry.

0 Votes 0 ·
ErinDavis-7013 avatar image
0 Votes"
ErinDavis-7013 answered ·

Hello,

We are using task scheduler to run the PowerShell code for the blob. We use it to download the latest differential and/or full.. We are using PowerShell 7 for the code. We have code for the differential each day and then one for the full on Sunday.

SQL Server is 2017.

We download the back up from the blob container to a network drive and then run SQL to restore.

When I download manually we never have an issue with the restore script.

When we use the PowerShell it will run fine for a while and the restore will work but sometimes it will either finish the download and I get the attached error when I try to restore, or it will just get stuck and not finish.





16139-image.png



image.png (80.9 KiB)
·
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.