Friday, October 23, 2009

Change the Default Backup Directory


I have used this on most of my servers so that when I click restore or Backup database it doesn’t go off to a directory under programme files on the C drive and goes to the root of the backup directory I use.

SQL 2005 version

This part of the script will display the current default backup directory.
DECLARE @BackupDirectory VARCHAR(100)
EXEC master..xp_regread @rootkey='HKEY_LOCAL_MACHINE',
@key='SOFTWARE\Microsoft\Microsoft SQL Server\MSSQL.1\MSSQLServer',
@value_name='BackupDirectory',
@BackupDirectory=@BackupDirectory OUTPUT
SELECT @BackupDirectory as BackupDirectory


This script will set G:\Maintenance\userData as the new default directory.
EXEC master..xp_regwrite
@rootkey='HKEY_LOCAL_MACHINE',
@key='SOFTWARE\Microsoft\Microsoft SQL Server\MSSQL.1\MSSQLServer',
@value_name='BackupDirectory',
@type='REG_SZ',
@value='G:\Maintenance\userData'


SQL 2000 version

DECLARE @BackupDirectory VARCHAR(100)
EXEC master..xp_regread @rootkey='HKEY_LOCAL_MACHINE',
@key='SOFTWARE\Microsoft\MsSQLServer\MsSQLServer',
@value_name='BackupDirectory',
@BackupDirectory=@BackupDirectory OUTPUT
SELECT @BackupDirectory as BackupDirectory


EXEC master..xp_regwrite
@rootkey='HKEY_LOCAL_MACHINE',
@key='SOFTWARE\Microsoft\MsSQLServer\MsSQLServer',
@value_name='BackupDirectory',
@type='REG_SZ',
@value='G:\Maintenance\userData'




No comments:

Post a Comment