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?
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:
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
If we run this command again we can see that this has changed:
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.
- 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
Last Update: 9/15/2008
About the author
View all my tips