How can i modify this script to backup a single database?

  • here is the script which works, backs up all databases. I need to backup one specific database only...

    -----------------------------------------------START----------------------------

    DECLARE @name VARCHAR(50) -- database name

    DECLARE @path VARCHAR(256) -- path for backup files

    DECLARE @fileName VARCHAR(256) -- filename for backup

    SET @path = 'C:\Backups\'

    DECLARE db_cursor CURSOR FOR

    SELECT name

    FROM master.dbo.sysdatabases

    WHERE name NOT IN ('tempdb')

    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

    WITH INIT

    FETCH NEXT FROM db_cursor INTO @name

    END

    CLOSE db_cursor

    DEALLOCATE db_cursor

    --------------------------------------END--------------------------------

    Can somone Help? Hope i posted this in the right area

  • DECLARE @name VARCHAR(50) -- database name

    DECLARE @path VARCHAR(256) -- path for backup files

    DECLARE @fileName VARCHAR(256) -- filename for backup

    SET @path = 'C:\Backups\'

    SET @name = 'Your DB Name HERE'

    SET @fileName = @path + @name + '.BAK'

    BACKUP DATABASE @name TO DISK = @fileName

    WITH INIT

    John Rowan

    ======================================================
    ======================================================
    Forum Etiquette: How to post data/code on a forum to get the best help[/url] - by Jeff Moden

  • The sql code within the cursor backups the db

    The cursor is running for every db in the server

    So concentrate in the cursor code, except fetch, etc codes replacing the cursor parameters with target database properties

    There is an other sample at MS SQL Server Backup Script

  • Guys - Thank you very much! Works perfectly. Take Care

Viewing 4 posts - 1 through 3 (of 3 total)

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