Friday, March 23, 2012

script to do full or differential backups for all databases

Can someone help me write a script to do full backups or differential
backups for all user databases on a server ?
ThanksHi,
Script to backup all databases
CREATE PROCEDURE BACKUP_SP @.Folder VARCHAR(100)
AS
begin
DECLARE @.NAME VARCHAR(100),
@.DBNAME VARCHAR(100)
DECLARE BACKUP_CUR CURSOR FOR
SELECT name FROM sysdatabases where name not
in('model','pubs','tempdb','no_rthwind')
OPEN BACKUP_CUR
FETCH NEXT FROM BACKUP_CUR INTO @.DBNAME
WHILE @.@.FETCH_STATUS=0
BEGIN
SELECT
@.NAME=ltrim(rtrim(@.folder))+@.@._SERVERNAM
E+'_'+@.DBNAME+'_'+ltr_im(rtrim(conve
rt
(char,getdate(),105)))+'Dump.b_ak'
BACKUP DATABASE @.DBNAME TO DISK = @.NAME WITH INIT , NOUNLOAD , NAME =
@.DBNAME, NOSKIP , STATS = 10
FETCH NEXT FROM BACKUP_CUR INTO @.DBNAME
END
CLOSE BACKUP_CUR
DEALLOCATE BACKUP_CUR
end
How to schedule
--
Enterprise Manager - Management -- SQL Agent -- Jobs -- Right click and
create new job.
Give a name to the Job and in Job step menthon this procedure with
foldername as parameter and
scdule the job to be executed based on requirement
Thanks
Hari
SQL Server MVP
"Hassan" <fatima_ja@.hotmail.com> wrote in message
news:uzarO8fRFHA.3156@.TK2MSFTNGP15.phx.gbl...
> Can someone help me write a script to do full backups or differential
> backups for all user databases on a server ?
> Thanks
>|||Hassan
Another one using undocumented stored procedure
EXEC sp_MSforeachdb
'IF N''?'' NOT IN(''model'' ,''tempdb'', ''distribution'', ''Northwind'',
''pubs'')
BEGIN
DECLARE @.sql varchar(1000);
set @.sql = ''BACKUP DATABASE '' + (''?'') + '' TO DISK =
''''D:\MSSQL2000\MSSQL\BACKUP'' + (''?'') + ''.bak'''' WITH INIT''
EXEC (@.sql)
END'
"Hassan" <fatima_ja@.hotmail.com> wrote in message
news:uzarO8fRFHA.3156@.TK2MSFTNGP15.phx.gbl...
> Can someone help me write a script to do full backups or differential
> backups for all user databases on a server ?
> Thanks
>|||Hassan,
Here is a link to one I know of.
http://www.planet-source-code.com/v...zysoftware.com/
Comprehensive, categorised, searchable collection of links to ASP & ASP.NET
resources...

No comments:

Post a Comment