Quantcast
Channel: Red Gate forums: SQL Backup 7
Viewing all articles
Browse latest Browse all 713

RE: Exclude Databases option

$
0
0
Each time a backup is ran with the EXCLUDE option, SQL Backup retrieves a list of active databases from SQL Server. It then removes the excluded databases from that list, then proceeds to back up the remaining databases.

You would need to maintain the exclusion list yourself, and add modify the SQL Backup command accordingly. Perhaps the following code snippet might provide some hints on how to do this:

Code:
CREATE TABLE SQBTEST_DBsToExclude (db nvarchar(128))
GO
INSERT INTO SQBTEST_DBsToExclude VALUES ('db1')
INSERT INTO SQBTEST_DBsToExclude VALUES ('db2')
INSERT INTO SQBTEST_DBsToExclude VALUES ('db3')
INSERT INTO SQBTEST_DBsToExclude VALUES ('db4')
INSERT INTO SQBTEST_DBsToExclude VALUES ('db5')
GO

DECLARE @cmd NVARCHAR(MAX)
DECLARE @dblist NVARCHAR(MAX)

SET @dblist =
(SELECT TOP 1
 SUBSTRING(
 (
  SELECT ( ', ' + db)
  FROM SQBTEST_DBsToExclude t1
  FOR XML PATH('')
 ), 3, 2048)
FROM SQBTEST_DBsToExclude)

SET @cmd = '-sql "BACKUP DATABASES EXCLUDE [' + @dblist + '] TO DISK = [<AUTO>]"'
SELECT @cmd
-- EXEC master..sqlbackup @cmd

Viewing all articles
Browse latest Browse all 713

Trending Articles