How can we help you today? How can we help you today?

Backup online databases only...

Answered my own question!
:!:
gscdba
0

Comments

4 comments

  • gscdba
    ok - seems dynamic SQL is the answer...



    EXEC sp_executesql @dSQL
    gscdba
    0
  • gscdba
    gscdba wrote:
    ok - seems dynamic SQL is the answer...



    EXEC sp_executesql @dSQL

    For those interested in a dynamic solution, I used this to generate the comma separated list of databases which are online and in full recovery model, then wrapped the SQLAgent job step generated by Red-Gate backup:
    DECLARE @sql NVARCHAR(MAX)
    DECLARE @listOfDatabasesForBackup NVARCHAR(MAX)
    SET @listOfDatabasesForBackup = (
    SELECT DISTINCT
        STUFF((SELECT
                [name] + ','
               FROM
                sys.[databases] AS D
               WHERE
                [state] = 0
                AND [recovery_model] = 1
              FOR
               XML PATH('')
              ), 1, 0, '') AS 'OnlineDatabases'
    FROM
        sys.[databases] AS D
    WHERE
        [state] = 0
        AND [recovery_model] = 1
    )
    SET @listOfDatabasesForBackup = LEFT(@listOfDatabasesForBackup, LEN(@listOfDatabasesForBackup) - 1)
    
    gscdba
    0
  • petey
    What sort of databases was SQL Backup picking up when you used the wildcard backup i.e.
    EXEC master..sqlbackup '-sql "BACKUP DATABASES [*] TO ... " '
    
    Thanks.
    petey
    0
  • gscdba
    petey wrote:
    What sort of databases was SQL Backup picking up when you used the wildcard backup i.e.
    EXEC master..sqlbackup '-sql "BACKUP DATABASES [*] TO ... " '
    
    Thanks.

    Was unaware of this wildcard feature - in any case, I needed a specific filter (online and full recovery model) so querying sys.databases gave me the flexibility.
    gscdba
    0

Add comment

Please sign in to leave a comment.