SQLDoctor
SQLDoctor

Reputation: 353

How to get backup path details once backup is completed using backup-sqldatabase in powershell

I am trying to take SQL DB backup from PowerShell using backup-sqldatabase module using the below script. The module works fine with taking DB backup however I am unable to figure out the backup file name for further use.

I have executed the below script but it is not taking $filename given by me also $db is null once the backup is completed.

I need to get the backup file name once the backup is completed.


$FileNAme="$backupUrlContainer"+"automationPOC.bak"

$db=Backup-SqlDatabase -BackupContainer $backupUrlContainer -SqlCredential $credentialName -Compression On -ServerInstance 'bp1amsdb419' -Database "Automation" -BackupFile $FileNAme ```

Upvotes: 0

Views: 316

Answers (1)

SQLDoctor
SQLDoctor

Reputation: 353

Below is the script in case we want to give a custom file name

$FileNAme="$backupUrlContainer"+"/"+"DBName.bak"
$db=Backup-SqlDatabase  -CompressionOption On -ServerInstance $serverName -Database $DBName -BackupFile $FileNAme -SQLCredential $credentialName

Upvotes: 0

Related Questions