SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Taking backup of all user database
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

SadafKhan85
Starting Member

India
8 Posts

Posted - 07/03/2013 :  07:46:41  Show Profile  Reply with Quote
In order to take automated backup of all user databases below is the query.
This query will eliminate use of manual backups for user databases, in order to fully automate this just create a SQL Agent job and write this query in the job and forget about taking any manual DB backups.

DECLARE @name VARCHAR(50) -- database name
DECLARE @path VARCHAR(256) -- path for backup files
DECLARE @fileName VARCHAR(256) -- filename for backup
DECLARE @fileDate VARCHAR(20) -- used for file name

SET @path = 'C:\DB_BKPUP\'

SELECT @fileDate = CONVERT(VARCHAR(20),GETDATE(),112)

DECLARE db_cursor CURSOR FOR
SELECT name
FROM master.dbo.sysdatabases
WHERE name NOT IN ('master','model','msdb','tempdb')

OPEN db_cursor
FETCH NEXT FROM db_cursor INTO @name

WHILE @@FETCH_STATUS = 0
BEGIN
SET @fileName = @path + @name + '_' + @fileDate + '.BAK'
BACKUP DATABASE @name TO DISK = @fileName

FETCH NEXT FROM db_cursor INTO @name
END

CLOSE db_cursor
DEALLOCATE db_cursor

madhivanan
Premature Yak Congratulator

India
22744 Posts

Posted - 07/29/2013 :  04:29:27  Show Profile  Send madhivanan a Yahoo! Message  Reply with Quote
Here is alternate way http://beyondrelational.com/modules/2/blogs/70/posts/10895/backup-all-databases.aspx

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

ahmeds08
Aged Yak Warrior

India
583 Posts

Posted - 07/29/2013 :  06:24:48  Show Profile  Send ahmeds08 a Yahoo! Message  Reply with Quote
Thanks

mohammad.javeed.ahmed@gmail.com
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.06 seconds. Powered By: Snitz Forums 2000