I encountered a roadblock while attempting to make a backup.
I am working from my workstation, running PowerShell scripts from my work station.
$server = "THESERVER" $db = "THEDB" $datetime = (Get-Date).ToString('MM-dd-yyyy-hh-mm-ss-tt'); $database1 = 'C:\temp\' + $db + '_' + $datetime + '.back'; $creds = Get-Credential 'admin' Backup-SqlDatabase -ServerInstance $server -Database $db -BackupFile $database1 -Credential $creds;
this reports an error:
Backup-SqlDatabase : System.Data.SqlClient.SqlError: Cannot open backup device 'C:\temp\THEDB_07-20-2021-04-14-06-PM.back'. Operating system error 3(The system cannot find the path specified.). At C:\Users\alilland\Documents\dev\bin\sql-server\db_backup.ps1:7 char:1 + Backup-SqlDatabase -ServerInstance $server -Database $db -BackupFile ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: (:) [Backup-SqlDatabase], SmoException + FullyQualifiedErrorId : ExecutionFailed,Microsoft.SqlServer.Management.PowerShell.BackupSqlDatabaseCommand
this error is taking place because my filepath is a local filepath to my machine, not a filepath that exists on the host of the sql-server, which fully makes sense, I completely understand why that error is taking place.
While looking at the docs here I came across the following PowerShell script for backing up a SqlDatabase and uploading to azure. It appears that I can pass in an azure container from my workstation, where I wouldnt need to be logged in to the host machine in order to make it work.
$credential = Get-Credential $container = 'https://<myStorageAccount>blob.core.windows.net/<myContainer>' $fileName = '<myDatabase>.bak' $server = '<myServer>' $database = '<myDatabase>' $backupFile = $container + '/' + $fileName Backup-SqlDatabase -ServerInstance $server -Database $database -BackupFile $backupFile -Credential $credential
before I go through the hassle of setting up an azure container with permissions, I know I can get the script to successfully run on the host, but will Backup-SqlDatabase accept an azure container path and upload to azure from my workstation without installing any CLI tools on the host machine?