﻿{"id":52,"date":"2014-10-01T09:53:50","date_gmt":"2014-10-01T09:53:50","guid":{"rendered":"http:\/\/www.codereview.co\/?p=52"},"modified":"2014-10-06T16:12:51","modified_gmt":"2014-10-06T16:12:51","slug":"how-to-change-the-sql-server-backup-folder","status":"publish","type":"post","link":"http:\/\/www.codereview.co\/index.php\/sql-server-tutorials\/how-to-change-the-sql-server-backup-folder\/","title":{"rendered":"How to change the Sql Server backup folder?"},"content":{"rendered":"<p><strong>Scenario proposal<br \/>\n<\/strong> When you install SQL Server the path for the installation is generally something such as the following: C:Program FilesMicrosoft SQL ServerMSSQL.2MSSQL.\u00a0 In this directory there are also folders for your DATA files and also your BACKUP files.\u00a0 Within SQL Server Management Studio you have the ability to change the default location for your Data and Log files for all new databases, but you can not change the default directory for your backups.\u00a0 Is it possible to change the default directory for backups, so it does not need to be specified each time I run a backup?<\/p>\n<p><!--more--><strong>Solution<br \/>\n<\/strong> The directories for the default data files, log files and backups are stored in the system registry.\u00a0 As mentioned already you have the ability to change the default data and log directories using SQL Server Management Studio, by right clicking on the server name and selecting properties and navigating to the Database Settings page as shown below.<\/p>\n<p><a href=\"http:\/\/dotnetsql.info\/net-sql\/index.php\/how-to-change-the-sql-server-backup-folder\/#\"><img decoding=\"async\" loading=\"lazy\" class=\"alignleft size-medium wp-image-552\" title=\"\" src=\"http:\/\/i2.wp.com\/dotnetsql.info\/net-sql\/wp-content\/uploads\/2014\/09\/1-300x251.jpg?resize=300%2C251\" class=\"grouped_elements\" rel=\"tc-fancybox-group52\" alt=\"\" data-recalc-dims=\"1\" \/><\/a><br \/>\n&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>But if you search through all of the pages under Database Settings you will not find anything that shows the default backup directory.\u00a0 To find this we need to look in the registry.<br \/>\nIf we open the registry using REGEDIT or some other tool and if you navigate to this key: <strong>HKEY_LOCAL_MACHINESOFTWAREMicrosoftMicrosoft SQL ServerMSSQL.2MSSQLServer <\/strong>or similar for your instance of SQL Server we can see the following information\u00a0\u00a0 The highlighted line below shows the default directory for the backups for this one instance.<br \/>\n<a href=\"http:\/\/dotnetsql.info\/net-sql\/index.php\/how-to-change-the-sql-server-backup-folder\/#\"><img decoding=\"async\" loading=\"lazy\" class=\"alignleft size-medium wp-image-558\" title=\"\" src=\"http:\/\/i1.wp.com\/dotnetsql.info\/net-sql\/wp-content\/uploads\/2014\/09\/3-300x182.jpg?resize=300%2C182\" class=\"grouped_elements\" rel=\"tc-fancybox-group52\" alt=\"\" data-recalc-dims=\"1\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>If you want to change the value you can edit the registry value and save the new location.\u00a0 So for this example let&#8217;s change it to &#8216;D:SQLBackups&#8217;.<br \/>\nIf I do a backup using SQL Management Studio and click on &#8220;Add&#8221; for a new destination file the following screen shows the default folder has now changed to &#8216;D:SQLBackups&#8217;.<br \/>\n<a href=\"http:\/\/dotnetsql.info\/net-sql\/index.php\/how-to-change-the-sql-server-backup-folder\/#\"><img decoding=\"async\" loading=\"lazy\" class=\"alignleft size-medium wp-image-557\" title=\"\" src=\"http:\/\/i0.wp.com\/dotnetsql.info\/net-sql\/wp-content\/uploads\/2014\/09\/2-300x162.jpg?resize=300%2C162\" class=\"grouped_elements\" rel=\"tc-fancybox-group52\" alt=\"\" data-recalc-dims=\"1\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>Another way to change the registry is to using the extended stored procedures XP_REGREAD and XP_REGWRITE.<br \/>\nTo read the value from the registry you can issue the following command:<br \/>\nDECLARE @BackupDirectory VARCHAR(100)<br \/>\nEXEC master..xp_regread @rootkey=&#8217;HKEY_LOCAL_MACHINE&#8217;,<br \/>\n@key=&#8217;SOFTWAREMicrosoftMicrosoft SQL ServerMSSQL.2MSSQLServer&#8217;,<br \/>\n@value_name=&#8217;BackupDirectory&#8217;,<br \/>\n@BackupDirectory=@BackupDirectory OUTPUT<br \/>\nSELECT @BackupDirectory<br \/>\nThis will provide the following output, since we changed the value above directly in the registry.<br \/>\n<a href=\"http:\/\/dotnetsql.info\/net-sql\/index.php\/how-to-change-the-sql-server-backup-folder\/#\"><img decoding=\"async\" loading=\"lazy\" class=\"alignleft size-full wp-image-559\" title=\"\" src=\"http:\/\/i1.wp.com\/dotnetsql.info\/net-sql\/wp-content\/uploads\/2014\/09\/4.jpg?resize=280%2C71\" class=\"grouped_elements\" rel=\"tc-fancybox-group52\" alt=\"\" data-recalc-dims=\"1\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>If we want to change this back to the default folder we can use the following command<br \/>\nEXEC master..xp_regwrite<br \/>\n@rootkey=&#8217;HKEY_LOCAL_MACHINE&#8217;,<br \/>\n@key=&#8217;SOFTWAREMicrosoftMicrosoft SQL ServerMSSQL.2MSSQLServer&#8217;,<br \/>\n@value_name=&#8217;BackupDirectory&#8217;,<br \/>\n@type=&#8217;REG_SZ&#8217;,<br \/>\n@value=&#8217;C:Program FilesMicrosoft SQL ServerMSSQL.2MSSQLBackup&#8217;<br \/>\nIf we run this command again we can see that this has changed:<br \/>\nDECLARE @BackupDirectory VARCHAR(100)<br \/>\nEXEC master..xp_regread @rootkey=&#8217;HKEY_LOCAL_MACHINE&#8217;,<br \/>\n@key=&#8217;SOFTWAREMicrosoftMicrosoft SQL ServerMSSQL.2MSSQLServer&#8217;,<br \/>\n@value_name=&#8217;BackupDirectory&#8217;,<br \/>\n@BackupDirectory=@BackupDirectory OUTPUT<br \/>\nSELECT @BackupDirectory<br \/>\n<a href=\"http:\/\/dotnetsql.info\/net-sql\/index.php\/how-to-change-the-sql-server-backup-folder\/#\"><img decoding=\"async\" loading=\"lazy\" class=\"alignleft size-medium wp-image-560\" title=\"\" src=\"http:\/\/i2.wp.com\/dotnetsql.info\/net-sql\/wp-content\/uploads\/2014\/09\/5-300x29.jpg?resize=300%2C29\" class=\"grouped_elements\" rel=\"tc-fancybox-group52\" alt=\"\" data-recalc-dims=\"1\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>To determine where SQL Server is installed you can right click on the server name, select Properties.\u00a0 The root directory as highlighted below will show you the corresponding install name for the instance such as &#8220;MSSQL2&#8221; highlighted below, so you know which registry entry needs to be changed.<br \/>\n<a href=\"http:\/\/dotnetsql.info\/net-sql\/index.php\/how-to-change-the-sql-server-backup-folder\/#\"><img decoding=\"async\" loading=\"lazy\" class=\"alignleft size-medium wp-image-561\" title=\"\" src=\"http:\/\/i0.wp.com\/dotnetsql.info\/net-sql\/wp-content\/uploads\/2014\/09\/6-300x126.jpg?resize=300%2C126\" class=\"grouped_elements\" rel=\"tc-fancybox-group52\" alt=\"\" data-recalc-dims=\"1\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>That&#8217;s all there is to it, so save yourself some time and change the default location.<\/p>\n<p><strong>Thanks for reading this article,<\/strong><\/p>\n<p><strong>Next steps :<\/strong><\/p>\n<ul>\n<li><b><strong>Add this script to your database toolkit<\/strong><\/b><\/li>\n<\/ul>\n<ul>\n<li><strong>Share this with your colleagues because Sharing is Learning<\/strong><\/li>\n<\/ul>\n<ul>\n<li><strong>Comment below if you need any assistance<\/strong><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>Scenario proposal When you install SQL Server the path for the installation is generally something such as the following: C:Program FilesMicrosoft SQL ServerMSSQL.2MSSQL.\u00a0 In this directory there are also folders for your DATA files and also your BACKUP files.\u00a0 Within SQL Server Management Studio you have the ability to change the default location for your [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[4,3],"tags":[10,19,16],"_links":{"self":[{"href":"http:\/\/www.codereview.co\/index.php\/wp-json\/wp\/v2\/posts\/52"}],"collection":[{"href":"http:\/\/www.codereview.co\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.codereview.co\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.codereview.co\/index.php\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/www.codereview.co\/index.php\/wp-json\/wp\/v2\/comments?post=52"}],"version-history":[{"count":5,"href":"http:\/\/www.codereview.co\/index.php\/wp-json\/wp\/v2\/posts\/52\/revisions"}],"predecessor-version":[{"id":179,"href":"http:\/\/www.codereview.co\/index.php\/wp-json\/wp\/v2\/posts\/52\/revisions\/179"}],"wp:attachment":[{"href":"http:\/\/www.codereview.co\/index.php\/wp-json\/wp\/v2\/media?parent=52"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.codereview.co\/index.php\/wp-json\/wp\/v2\/categories?post=52"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.codereview.co\/index.php\/wp-json\/wp\/v2\/tags?post=52"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}