Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Backup history


Backup history

Author
Message
river1
river1
UDP Broadcaster
UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)

Group: General Forum Members
Points: 1460 Visits: 1366
Hi,

I have created a job that makes backups.

Code sample:

declare @date as varchar(25)
Declare @Nome as varchar(50)
DECLARE Backups CURSOR FOR
SELECT name from sys.databases where state =0
order by name
set @date = convert(varchar,getdate(),120)
set @date = replace(replace(@date,'-',''),':','')
OPEN backups

FETCH NEXT FROM backups INTO @nome

WHILE @@FETCH_STATUS = 0
BEGIN




exec('backup database '+@nome+' to disk =''c:\database_backups\'+@nome+'\'+@nome+'_'+@date+'.BAK''')



FETCH NEXT FROM backups INTO @nome
END

CLOSE backups
DEALLOCATE backups




The backups that are created by this job are name as:

e.g: SGI_20101209 111200.BAK

Now i would like to add to the name of the backup, the number of backup.

If the backup is the 3 backup of this database, i would like that the name become like this:

SGI_3_20101209 111200.BAK

Where can i get the information of the number of backup already made to this database?
george sibbald
george sibbald
SSCrazy Eights
SSCrazy Eights (9K reputation)SSCrazy Eights (9K reputation)SSCrazy Eights (9K reputation)SSCrazy Eights (9K reputation)SSCrazy Eights (9K reputation)SSCrazy Eights (9K reputation)SSCrazy Eights (9K reputation)SSCrazy Eights (9K reputation)

Group: General Forum Members
Points: 8992 Visits: 13687
select count(*) from msdb..backupset where database_name = 'yourdb' and type = 'D'

However older backup history can be purged from this table by cleanup operations so unless you never run this purge and just allow the table to grow ad infinitum the info could be wrong. This table has an identity column backup_set_id you could use as an ever increasing number, but it would not reflect the actual number of backups for that database.

---------------------------------------------------------------------
river1
river1
UDP Broadcaster
UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)

Group: General Forum Members
Points: 1460 Visits: 1366
What did you meant buy "cleanup operations" ?


Thank you
John Mitchell-245523
John Mitchell-245523
SSChampion
SSChampion (12K reputation)SSChampion (12K reputation)SSChampion (12K reputation)SSChampion (12K reputation)SSChampion (12K reputation)SSChampion (12K reputation)SSChampion (12K reputation)SSChampion (12K reputation)

Group: General Forum Members
Points: 12111 Visits: 15743
There's a stored procedure sp_delete_backuphistory that you can use to purge old backup records from the msdb database.

John
river1
river1
UDP Broadcaster
UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)

Group: General Forum Members
Points: 1460 Visits: 1366
we don't use that.

Thanks for the tip.
george sibbald
george sibbald
SSCrazy Eights
SSCrazy Eights (9K reputation)SSCrazy Eights (9K reputation)SSCrazy Eights (9K reputation)SSCrazy Eights (9K reputation)SSCrazy Eights (9K reputation)SSCrazy Eights (9K reputation)SSCrazy Eights (9K reputation)SSCrazy Eights (9K reputation)

Group: General Forum Members
Points: 8992 Visits: 13687
The above proc would also be run if you use the history cleanup task in a maintenance plan and select Backup and restore history

---------------------------------------------------------------------
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search