Announcement

Collapse

Attention

Support provided within these forums is community based and provided as-is without guarantee or warranty and is only intended to be supplemental to vendor based support offerings.
See more
See less

SQL Backup Script with SSISDB Master Key

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • SQL Backup Script with SSISDB Master Key

    Code:
    DECLARE @path VARCHAR(256)
    SET @path = 'E:\SQLBACKUPS\'
    EXECUTE master.dbo.xp_create_subdir @path
    DECLARE @query nvarchar(max);
    
    DECLARE @name VARCHAR(50) -- database name
    DECLARE @fileName VARCHAR(256) -- filename for backup
    
    DECLARE db_cursor CURSOR FOR
    SELECT name
    FROM master.dbo.sysdatabases
    WHERE name NOT IN ('master','model','msdb','tempdb') -- exclude these databases
    
    OPEN db_cursor
    FETCH NEXT FROM db_cursor INTO @name
    
    WHILE @@FETCH_STATUS = 0
    BEGIN
    SET @fileName = @path + @name + '.BAK'
    BACKUP DATABASE @name TO DISK = @fileName
    FETCH NEXT FROM db_cursor INTO @name
    END
    
    CLOSE db_cursor
    DEALLOCATE db_cursor
    
    IF EXISTS
    (
    SELECT name FROM master.dbo.sysdatabases
    WHERE name = N'SSISDB'
    )
    BEGIN
    
    
    USE SSISDB
    
    DECLARE @command NVARCHAR(MAX)
    SET @command = 'BACKUP MASTER KEY TO FILE = ''' + @path + N'SSISDB_MASTERKEY'' '
    + 'ENCRYPTION BY PASSWORD = ''Password1$'';'
    exec sp_executesql @command
    
    
    END
    ELSE
    BEGIN
    print 'SSISDB DOES NOT EXIST - COULD NOT BACKUP MASTER KEY'
    END
Working...
X