Sunday, March 25, 2012

Backup Setup

I am trying to setup the following and was hoping if someone could tell me a more efficient way to set this up. I am not using the maintenance plan or wizard cause Ive had nothing but issues with them:

1. Create a backup device for each day of the week (Sunday - Saturday)

2. Create a job using T-SQL to run maintenance (Rebuild Indexes) and then at the conclusion of the maintenance run a full backup every night at midnight. I would need once job for each day of the week and store them on the proper backup device.

BACKUP DATABASE [DBS1] TO [Sunday Backup] WITH NOFORMAT, NOINIT, NAME = N'DBS1-Full Database Backup', SKIP, NOREWIND, NOUNLOAD, STATS = 10, CHECKSUM

GO

declare @.backupSetId as int

select @.backupSetId = position from msdb..backupset where database_name=N'DBS1' and backup_set_id=(select max(backup_set_id) from msdb..backupset where database_name=N'DBS1' )

if @.backupSetId is null begin raiserror(N'Verify failed. Backup information for database ''DBS1'' not found.', 16, 1) end

RESTORE VERIFYONLY FROM [Sunday Backup] WITH FILE = @.backupSetId, NOUNLOAD, NOREWIND

GO

3. Create a job using T-SQL for transaction log backups to run every hour and store them in the proper backup device. I would need one job for each day of the week.

BACKUP LOG [DBS1 [Sunday Backup] WITH NOFORMAT, NOINIT,

NAME = N'DBS1-Transaction Log Backup', SKIP, NOREWIND, NOUNLOAD, STATS = 10, CHECKSUM

GO

declare @.backupSetId as int

select @.backupSetId = position from msdb..backupset where database_name=N'DBS1' and backup_set_id=(select max(backup_set_id) from msdb..backupset where database_name=N'DBS1' )

if @.backupSetId is null begin raiserror(N'Verify failed. Backup information for database ''DBS1"' not found.', 16, 1) end

RESTORE VERIFYONLY FROM [Sunday Backup] WITH FILE = @.backupSetId, NOUNLOAD, NOREWIND

GO

This method would give me 7 backups devices and 14 jobs but at least things would be organized nice and neat. Im sure there is a better way to do this so I am looking for some help. Any help would be much appreciated.

Thanks

One simplification would be to have the script build the name of the backup device based on the current day of the week. This way you have one backup job and one log backup job that each run every day.

The following would be an example of building the backup device name:

DECLARE @.BackupDev AS NVARCHAR(30)

select @.BackupDev = DATENAME(dw,GETDATE()) + N'_BACKUP_DEV'

No comments:

Post a Comment