Generate script

  • HI,
    We have 100 databases and need to take tail back up. I'm trying to generate sql script for all 100 databases. Can you please advise?

    BACKUP LOG DB1 TO DISK = N'Z:\DR\Taillog_Backup\DB1.trn'
    WITH NORECOVERY 
    GO

    I'm just getting name but not sure how to include the path 

    SELECT 'Backup log '''+NAME+'''' FROM sys.databases

  • gary1 - Thursday, January 4, 2018 10:59 AM

    HI,
    We have 100 databases and need to take tail back up. I'm trying to generate sql script for all 100 databases. Can you please advise?

    BACKUP LOG DB1 TO DISK = N'Z:\DR\Taillog_Backup\DB1.trn'
    WITH NORECOVERY 
    GO

    I'm just getting name but not sure how to include the path 

    SELECT 'Backup log '''+NAME+'''' FROM sys.databases

    You just need to keep building the string.

    SELECT 'BACKUP LOG ' + QUOTENAME(name) + ' TO DISK = N''Z:\DR\Taillog_Backup\' + name + '.trn''
    WITH NORECOVERY
    GO'
    FROM sys.databases

    Luis C.
    General Disclaimer:
    Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

    How to post data/code on a forum to get the best help: Option 1 / Option 2
  • Luis Cazares - Thursday, January 4, 2018 11:45 AM

    gary1 - Thursday, January 4, 2018 10:59 AM

    HI,
    We have 100 databases and need to take tail back up. I'm trying to generate sql script for all 100 databases. Can you please advise?

    BACKUP LOG DB1 TO DISK = N'Z:\DR\Taillog_Backup\DB1.trn'
    WITH NORECOVERY 
    GO

    I'm just getting name but not sure how to include the path 

    SELECT 'Backup log '''+NAME+'''' FROM sys.databases

    You just need to keep building the string.

    SELECT 'BACKUP LOG ' + QUOTENAME(name) + ' TO DISK = N''Z:\DR\Taillog_Backup\' + name + '.trn''
    WITH NORECOVERY
    GO'
    FROM sys.databases

    Thanks so much.
    How to put the GO statement in next line?

  • I'd add a where clause to the query to filter out any databases that happen to be using the simple recovery model.

  • Lynn Pettis - Thursday, January 4, 2018 3:41 PM

    I'd add a where clause to the query to filter out any databases that happen to be using the simple recovery model.

    I used this:

    SELECT 'BACKUP LOG ' + QUOTENAME(primary_database) + ' TO DISK = N''Z:\DR\Taillog_Backup\' + primary_database + '.trn''
    WITH NORECOVERY
    GO'
    FROM msdb.dbo.log_shipping_primary_databases

  • Lynn Pettis - Thursday, January 4, 2018 3:41 PM

    I'd add a where clause to the query to filter out any databases that happen to be using the simple recovery model.

    +1 and also a clause filtering for ONLINE.

    ...

Viewing 6 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic. Login to reply