solving sql server problems for millions of dbas and developers since 2006



SQL Server DBA Tips SQL Server Developer Tips SQL Server Business Intelligence Tips SQL Server Career Tips SQL Server Tip Categories SQL Server Tutorials SQL Server Webcasts SQL Server Whitepapers SQL Server Tools SQL Server Questions and Answers MSSQLTips Authors About MSSQLTips SQL Server User Groups MSSLQTips Giveaways MSSQLTips Advertising Options

MSSQLTips Facebook Page MSSQLTips LinkedIn Page MSSQLTips RSS Feed MSSQLTips Twitter Page MSSQLTips Google+ Page





Changing the default SQL Server backup folder

By: | Read Comments (13) | Print

Greg is the President of Edgewood Solutions and a co-founder of MSSQLTips.com.

Related Tips: More

Problem
When you install SQL Server the path for the installation is generally something such as the following: C:\Program Files\Microsoft SQL Server\MSSQL.2\MSSQL.  In this directory there are also folders for your DATA files and also your BACKUP files.  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.  Is it possible to change the default directory for backups, so it does not need to be specified each time I run a backup?

Solution
The directories for the default data files, log files and backups are stored in the system registry.  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.

But if you search through all of the pages under Database Settings you will not find anything that shows the default backup directory.  To find this we need to look in the registry.

If we open the registry using REGEDIT or some other tool and if you navigate to this key: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server\MSSQL.2\MSSQLServer or similar for your instance of SQL Server we can see the following information   The highlighted line below shows the default directory for the backups for this one instance.

 

If you want to change the value you can edit the registry value and save the new location.  So for this example let's change it to 'D:\SQLBackups'.

If I do a backup using SQL Management Studio and click on "Add" for a new destination file the following screen shows the default folder has now changed to 'D:\SQLBackups'.

Another way to change the registry is to using the extended stored procedures XP_REGREAD and XP_REGWRITE.

To read the value from the registry you can issue the following command:

DECLARE @BackupDirectory VARCHAR(100)
EXEC master..xp_regread @rootkey='HKEY_LOCAL_MACHINE',
  
@key='SOFTWARE\Microsoft\Microsoft SQL Server\MSSQL.2\MSSQLServer',
  
@value_name='BackupDirectory',
  
@BackupDirectory=@BackupDirectory OUTPUT
SELECT @BackupDirectory

This will provide the following output, since we changed the value above directly in the registry.

If we want to change this back to the default folder we can use the following command

EXEC master..xp_regwrite
     
@rootkey='HKEY_LOCAL_MACHINE',
     
@key='SOFTWARE\Microsoft\Microsoft SQL Server\MSSQL.2\MSSQLServer',
     
@value_name='BackupDirectory',
     
@type='REG_SZ',
     
@value='C:\Program Files\Microsoft SQL Server\MSSQL.2\MSSQL\Backup'

If we run this command again we can see that this has changed:

DECLARE @BackupDirectory VARCHAR(100)
EXEC master..xp_regread @rootkey='HKEY_LOCAL_MACHINE',
  
@key='SOFTWARE\Microsoft\Microsoft SQL Server\MSSQL.2\MSSQLServer',
  
@value_name='BackupDirectory',
  
@BackupDirectory=@BackupDirectory OUTPUT
SELECT @BackupDirectory

To determine where SQL Server is installed you can right click on the server name, select Properties.  The root directory as highlighted below will show you the corresponding install name for the instance such as "MSSQL2" highlighted below, so you know which registry entry needs to be changed.

That's all there is to it, so save yourself some time and change the default location.

Next Steps

  • If you are tired of changing the location for your backups each time you do a backup you can make this one time registry change and not have to select a the folder each time.  In addition, this works the same if you use the T-SQL BACKUP commands.  You will not need to specify the folder just the file name and the backups will work without a problem.
  • Take a look at these other backup tips


Related Tips: More | Become a paid author


Last Update: 9/15/2008

Share: Share 






Comments and Feedback:

Monday, September 15, 2008 - 11:42:21 AM - SAinCA Read The Tip

The tip is useful for 2005+ - is there an equivalent for SS2K, please?


Monday, September 15, 2008 - 6:02:25 PM - aprato Read The Tip

 There's a similar screen in SQL 2000

In Enterprise Manager, right-click on the server name and choose Properties and then the Database Settings tab


Monday, September 15, 2008 - 6:06:16 PM - SAinCA Read The Tip

Yep - known...

How does one CHANGE the default backup destination folder?  There doesn't appear to be an equivalent registry area for 2K...  Poster is NOT a DBA, hence the seemingly "basic" nature of the question...

AND, do I have to make the change to both nodes of the cluster, if indeed it is a registry change that is required...?


Wednesday, September 17, 2008 - 6:21:36 PM - aprato Read The Tip

Do you have a BackupDirectory key under HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\MSSQLServer\MSSQLServer ? I don't have access to SQL Server 2000 at the moment and I'll have to install it to check the installed reg keys


Wednesday, September 24, 2008 - 4:42:06 AM - MikeHinds Read The Tip

[quote user="SAinCA"]

How does one CHANGE the default backup destination folder?  There doesn't appear to be an equivalent registry area for 2K.

[/quote]

Create ONE Backup device using Enterprise Manager, which will then use your chosen backup folder as the default (one of many useful behaviors that went away in 2005).

[quote user="SAinCA"]

AND, do I have to make the change to both nodes of the cluster, if indeed it is a registry change that is required...?

[/quote]

I've done this on a cluster, but can't verify fully that this is the case without actually failing one over to test. Not knowing where the default is stored: if in the registry, you may need to do it twice; but if it's stored in Master or Msdb, then seems like you're covered.


Wednesday, September 24, 2008 - 5:04:50 AM - psivakumar Read The Tip

Is there a way to point to a remote server's shared folder(s)? This will make backup to remote servers and keep a copy standing by for better recoverability. Currently, I am backing up in the local server (SQL) and then copying to remote server.

 

Thanks


Wednesday, September 24, 2008 - 9:44:36 AM - SAinCA Read The Tip

Thanks, Mike, it had to be "something different" for 2K.  Will give it a whirl on our test box...


Wednesday, September 24, 2008 - 9:48:20 AM - SAinCA Read The Tip

To do what you want, I'd recommend using Red-Gate's SQL Backup as it runs exceptionally quickly, including compression (HUGE disk saving), and has a simple "copy to network drive" option you can employ.  The guys here tried local and network-copy using native commands but it became a pain - they were glad of SQL Backup's feature...  Hope you can justify the minimal expense for what the tool delivers.


Tuesday, February 02, 2010 - 9:15:27 AM - admin Read The Tip

For SQL Server 2000 it is basically the same thing. 

Here is an example of the key path for a SQL 2000 installation 

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server\SQL2000\MSSQLServer

The parameter is called "BackupDirectory"


Friday, April 08, 2011 - 4:58:34 PM - Sam Read The Tip

This worked great for new databases that are created.  However, the default location for databases that existed before the registry change still defaults to the old location.  Is there a fix for that?


Friday, April 08, 2011 - 5:06:31 PM - Greg Robidoux Read The Tip

Sam are you saying that for newer databases the backups go to the new backup location, but for older databases the backups go to the older backup folder? Just want to make sure I understand the need.


Friday, April 08, 2011 - 6:09:24 PM - Sam Read The Tip

Correct.  I'm able to change the location and remove the old location, but every time I right click-->all tasks-->back up, the default location would revert back to what it was before I made the change.


Saturday, April 09, 2011 - 8:08:55 AM - Greg Robidoux Read The Tip

Hi Sam, I just tried this on SQL Server 2008 and the GUI showed the new location for me after I made the change.  I also had done a backup for this database prior to changing the location and it still showed the new location using the GUI.

I am not sure why it is not working consistently for you.

You could also try this to see if the backup for one of these databases goes to the new location and put in your database name and the name of the file for the backup file without specifying a backup location.

BACKUP DATABASE dbName TO DISK = 'fileName'

BACKUP DATABASE master TO DISK = 'master_test.bak'



Post a Comment or Question

Keep it clean and stay on the subject or we may delete your comment.
Your email address is not published. Required fields are marked with an asterisk (*)

*Name   *Email   Notify for updates
Comments
*Enter Code refresh code


 

Sponsor Information
"SQL doctor is the best SQL product on the market, by far. All of Idera's tools are great, but this is the icing on the cake!"

Time-strapped database professionals use SQL Monitor to look after their servers. Try it online.

SQL Servers keeping you up at night? Contact the Edgewood SQL Server DBAs for a Health Check. Prices start at $995.

Get SQL Server Tips Straight from Kevin Kline.

Solving SQL Server problems for millions of DBAs and Devs since 2006. Join now.

Free web casts for DBAs and Developers on Performance Tuning, Development, Administration and more....


Copyright (c) 2006-2012 Edgewood Solutions, LLC All rights reserved
privacy | disclaimer | copyright | advertise | about
authors | contribute | feedback | giveaways | user groups
Some names and products listed are the registered trademarks of their respective owners.


Edgewood Solutions LLC | MSSharePointTips.com | MSSQLTips.com