3

I'm trying to find out how to detect if a backup device exists using T-SQL.

This is how I create my backup device:

EXEC master.dbo.sp_addumpdevice 
 @devtype = N'disk', 
 @logicalname = N'TestTest', 
 @physicalname = N'C:\Program Files\Microsoft SQL Server\MSSQL10_50.PTC_SQLPROD\MSSQL\Backup\TestTest.bak'

but I can't find how to detect if it already exists first.

András Váczi
31.8k13 gold badges103 silver badges152 bronze badges
asked Oct 30, 2012 at 11:14

1 Answer 1

3

The sys.backup_devices table should contain details on existing backup devices, so try checking to see if there's a row there first:

IF NOT EXISTS (SELECT NULL
 FROM sys.backup_devices
 WHERE [Name] = N'TestTest'
 AND [Type] = 2) -- 2 = 'Disk'; see MSDN
 EXEC master.dbo.Sp_addumpdevice
 @devtype = N'disk',
 @logicalname = N'TestTest',
 @physicalname = N'C:\Program Files\Microsoft SQL Server\MSSQL10_50.PTC_SQLPROD\MSSQL\Backup\TestTest.bak'

The documentation for the sys.backup_devices table can be found here: http://msdn.microsoft.com/en-us/library/ms178018%28v=sql.100%29.aspx

answered Oct 31, 2012 at 11:25

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.