Created
December 20, 2017 12:47
-
-
Save lyhcode/9897687ff7221e12f30ef8dbb653dc27 to your computer and use it in GitHub Desktop.
PowerShell script for sql server database backup with timestamp file name.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$dt = Get-Date -Format yyyyMMddHHmmss | |
$dbname = 'dfi' | |
$username = 'DFINewWebsiteSI' | |
#read-host -assecurestring | convertfrom-securestring | out-file sqlsecure.txt | |
$password = Get-Content sqlsecure.txt | |
$secpasswd = $password | ConvertTo-SecureString | |
$credential = New-Object System.Management.Automation.PSCredential -ArgumentList $username,$secpasswd | |
$bakfile = "C:\Program Files\Microsoft SQL Server\MSSQL13.MSSQLSERVER\MSSQL\Backup\dfi_$($dt).bak" | |
Write-Output "backup database to disk file = $bakfile" | |
Backup-SqlDatabase -ServerInstance DFINW -Database $dbname -Credential $credential -BackupFile $bakfile |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment