{"id":90,"date":"2018-10-05T05:43:40","date_gmt":"2018-10-05T05:43:40","guid":{"rendered":"http:\/\/www.spktechfit.com\/?p=90"},"modified":"2018-10-05T05:43:40","modified_gmt":"2018-10-05T05:43:40","slug":"how-to-easily-backup-ms-sql-databases-using-powershell","status":"publish","type":"post","link":"https:\/\/www.spktechfit.com\/?p=90","title":{"rendered":"How to (Easily) backup MS SQL Databases using Powershell"},"content":{"rendered":"<p>Backing up SQL databases with Powershell is quite useful and is probably easier than you think. This can be used in situations where you only have the SQL Server Express edition installed and can&#8217;t manage backups through the SQL Management Studio, or if you just want to do some one off backups<\/p>\n<div class=\"action-bar enabled\">\n<h3 class=\"title\">Install SQLServer Powershell module<\/h3>\n<div class=\"action-links\">\u00a01. Open a Powershell window as Administrator<\/div>\n<div class=\"action-links\">\u00a0 2. Run the command: <em>Install-Module -Name SqlServer<\/em><\/div>\n<\/div>\n<div><\/div>\n<div>\n<div class=\"action-bar enabled\">\n<h3 class=\"title\">Get a list of all databases on a remote server\u00a0<i class=\"sui-icon sui-icon-trash sui-icon--16\"><\/i><\/h3>\n<\/div>\n<div class=\"item-content howto-step--form-content\">\n<p>This will prompt you for credentials to use, then get a list of all the databases in the remote server SQL instance:<br \/>\n<em>Get-SqlDatabase -Credential $Credential -ServerInstance yoursqlserver<\/em><\/p>\n<div class=\"action-bar enabled\">\n<h3 class=\"title\">Backing up a single database<i class=\"sui-icon sui-icon-drag sui-icon--16 edit-step--drag\"><\/i>\u00a0<i class=\"sui-icon sui-icon-edit sui-icon--16\"><\/i>\u00a0<i class=\"sui-icon sui-icon-trash sui-icon--16\"><\/i><\/h3>\n<\/div>\n<div class=\"item-content howto-step--form-content\">\n<p>The following will backup a single database to the default MS SQL backup directory, with the default backup name:<br \/>\n<em>Backup-SqlDatabase -ServerInstance yourSQLServer -Database yourdatabase<\/em><\/p>\n<p>By adding the &#8216;BackupFile&#8217; parameter we can select the location of where to put the backup:<br \/>\n<em>Backup-SqlDatabase -ServerInstance yourSQLServer -Database yourdatabase -BackupFile &#8220;C:\\Backups\\BackupName.bak&#8221;<\/em><\/p>\n<\/div>\n<div class=\"action-bar enabled\">\n<h3 class=\"title\">Backup all databases in an SQL instance and name with todays date<i class=\"sui-icon sui-icon-drag sui-icon--16 edit-step--drag\"><\/i>\u00a0<i class=\"sui-icon sui-icon-edit sui-icon--16\"><\/i>\u00a0<i class=\"sui-icon sui-icon-trash sui-icon--16\"><\/i><\/h3>\n<\/div>\n<div class=\"item-content howto-step--form-content\">\n<p>The following gets all the databases in an instance (except the temp database) , then backups these databases and names them with todays date:<br \/>\n<em>Get-SqlDatabase -Credential $Credential -ServerInstance yourSQLServer | foreach{<\/em><br \/>\n<em>Backup-SqlDatabase -DatabaseObject $_ -BackupFile &#8220;$($_.NAME)_db_$(Get-Date -UFormat %Y%m%d%H%M).bak&#8221;}<\/em><\/p>\n<\/div>\n<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Backing up SQL databases with Powershell is quite useful and is probably easier than you think. This can be used in situations where you only have the SQL Server Express edition installed and can&#8217;t manage backups through the SQL Management Studio, or if you just want to do some one off backups Install SQLServer Powershell [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[8,2,3],"tags":[],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.spktechfit.com\/index.php?rest_route=\/wp\/v2\/posts\/90"}],"collection":[{"href":"https:\/\/www.spktechfit.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.spktechfit.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.spktechfit.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.spktechfit.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=90"}],"version-history":[{"count":1,"href":"https:\/\/www.spktechfit.com\/index.php?rest_route=\/wp\/v2\/posts\/90\/revisions"}],"predecessor-version":[{"id":91,"href":"https:\/\/www.spktechfit.com\/index.php?rest_route=\/wp\/v2\/posts\/90\/revisions\/91"}],"wp:attachment":[{"href":"https:\/\/www.spktechfit.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=90"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.spktechfit.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=90"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.spktechfit.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=90"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}