Skip to content

Instantly share code, notes, and snippets.

@raducugheorghe
Created February 6, 2015 09:01
Show Gist options
  • Save raducugheorghe/43ae1cb1fd6ea93e47e6 to your computer and use it in GitHub Desktop.
Save raducugheorghe/43ae1cb1fd6ea93e47e6 to your computer and use it in GitHub Desktop.
[Powershell] Backup website and database from script
Import-Module SQLPS -DisableNameChecking
Import-Module PSCX
$dt = Get-Date -Format yyyyMMddHHmmss
$dbname = 'DBNAME'
Backup-SqlDatabase -ServerInstance .\SQLEXPRESS -Database $dbname -BackupFile "C:\Backups\$($dbname)_db_$($dt).bak"
write-zip "C:\WebSites\SITENAME\*" "C:\Backups\$($dbname)_website_$($dt).zip"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment