Re: Daily Backup Filename
From: Hari Prasad (hari_prasad_k_at_hotmail.com)
Date: 08/19/04
- Next message: Itzik Ben-Gan: "Re: Combinations"
- Previous message: Alejandro Mesa: "RE: Two Counts in one results window?"
- In reply to: Jon Glazer: "Daily Backup Filename"
- Next in thread: Jon Glazer: "Re: Daily Backup Filename"
- Reply: Jon Glazer: "Re: Daily Backup Filename"
- Messages sorted by: [ date ] [ thread ]
Date: Thu, 19 Aug 2004 22:26:31 +0530
Hi,
Execute the below procedure inMaster database and schedule it using
Management -- SQL Agent-- Jobs -- Add jobs with TSQL type option. THis
procedure will backup all the databases except
'model','pubs','tempdb','northwind'. This will backup the databases with
DBNAME_DD-MM-YYY Y_DUMP.BAK
CREATE PROCEDURE BACKUP_SP @PATH VARCHAR(200) AS
BEGIN
SET NOCOUNT ON
DECLARE @NAME VARCHAR(100),
DECLARE @DBNAME VARCHAR(100)
DECLARE BACKUP_CUR CURSOR FOR
SELECT name FROM master..Sysdatabases where name not in
('model','pubs','tempdb','northwind')
OPEN BACKUP_CUR
FETCH NEXT FROM BACKUP_CUR INTO @DBNAME
WHILE @@FETCH_STATUS=0
BEGIN
SELECT NAME=@PATH+@DBNAME+'_'+ltrim (rtrim
(convert(char,getdate(),105)))+'Dump.bak'
BACKUP DATABASE @DBNAME TO DISK = @NAME WITH INIT , NOUNLOAD ,NAME
= @DBNAME, NOSKIP, STATS = 10, NOFORMAT
FETCH NEXT FROM BACKUP_CUR INTO @DBNAME
END
CLOSE BACKUP_CUR
DEALLOCATE BACKUP_CUR
END
How to Execute
This procedure will take @PATH as the input parameter, Say you have to
backup the database to D:\SQLBACKUP folder then the execution will be
EXEC BACKUP_SP 'D:\SQLBACKUP\'
This will backup all the databases to backup files based on database name
and date . So arrange a purging mechanism to delete the old files.
Thanks
Hari
MCDBA
"Jon Glazer" <jglazer.deleteme@adconn.com> wrote in message
news:Ld4Vc.23502$Nl1.16115@fe1.columbus.rr.com...
> I would like to run a backup daily using the backup command. However I
want
> the file to be named after whatever day it is. Monday, tuesday, etc...
>
> Can anyone help me do this? How do you pull the day of the week off the
> system?
>
> Thanks!
>
>
- Next message: Itzik Ben-Gan: "Re: Combinations"
- Previous message: Alejandro Mesa: "RE: Two Counts in one results window?"
- In reply to: Jon Glazer: "Daily Backup Filename"
- Next in thread: Jon Glazer: "Re: Daily Backup Filename"
- Reply: Jon Glazer: "Re: Daily Backup Filename"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|