SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Copies of backups.


Copies of backups.

Author
Message
MSSQL_NOOB
MSSQL_NOOB
SSC Veteran
SSC Veteran (271 reputation)SSC Veteran (271 reputation)SSC Veteran (271 reputation)SSC Veteran (271 reputation)SSC Veteran (271 reputation)SSC Veteran (271 reputation)SSC Veteran (271 reputation)SSC Veteran (271 reputation)

Group: General Forum Members
Points: 271 Visits: 173
I'm trying to figure out a plan to keep a consistent copies of backups for a few internal db on server.

Job 1 - Full Backups : Only Monday - Friday since it's strictly internal use.
Job 2 - Delete Full Backups: Everyday.

With the schedule above, I'm not getting a consistent number of copies of full backups. I figured here's an example of the schedule.

Today's date File Deleted File remained Number of copies
1/20/2014 1/15/2014 1/16/,1/17,1/20 3
1/21/2014 1/16/2014 1/17,1/20,1/21 3
1/22/2014 1/17/2014 1/20,1/21,1/22 3
1/23/2014 No file 1/20,1/21,1/22,1/23 4
1/24/2014 No file 1/20,1/21,1/22,1/23,1/24 5
1/25/2014 1/20/2014 1/21,1/22,1/23,1/24 4
1/26/2014 1/21/2014 1/22,1/23,1/24 3
1/27/2014 1/22/2014 1/23,1/24,1/27 3

Some explanation of the schedule above.
If today's date is 1/20/2014, and I set delete backups that is older than 4 days; Job 2 will delete 1/15/2014's backup file and everything that is older than 1/16/2014.
What remains on the server are backups from 1/16/2014, 1/17/2014, 1/20/2014 - essentially have 3 copies on the network.

All is fine until 1/24/2014 (Friday) - when Job 2 runs, it'll delete everything that's older than 1/20/2014; leaving 1/20/2014, 1/21/2014, 1/22/2014, 1/23/2014 and 1/24/2014 (5 copies) backups on the network.

I would like to keep 3 copies at any time. The only consistent number of copies I can get is if I delete 6 days and older - having 5 copies on the network.
It seems I'm stuck on how to accomplish that consistency if I just want 3 copies.
Keith Tate
Keith Tate
SSCrazy
SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)

Group: General Forum Members
Points: 2352 Visits: 979
The issue comes down to not wanting to count weekends as days in your delete statement. I would recommend a date table that has a list of dates and has a day of the week column or at least a Weekend flag or you can create a date range using a cte. Once you have that exclude all days that are weekends and then add a row number to the result set and delete everything that is older than or equal to the date that equals 4 in your result set.
declare @startDate date
, @endDate date

select @startDate = getdate()
select @endDate = dateadd(dd,-7,@startDate)

;with cte as (
select @startDate as dt
union all
select dateadd(day,-1,dt)
from cte
where dateadd(day,-1,dt) >= @endDate
)

SELECT
dt
, ROW_NUMBER() over(order by dt desc) rn
FROM cte
where DATEPART(dw,dt) not in (1,7)

In this case (today) it would mean delete everything older than or equal to the 17th. If it was the 24th then you would delete everything older than or equal to the 21st etc.
Play around with the code and see if that will work for you.



Microsoft Certified Master - SQL Server 2008
Follow me on twitter: @keith_tate

Forum Etiquette: How to post data/code on a forum to get the best help
MSSQL_NOOB
MSSQL_NOOB
SSC Veteran
SSC Veteran (271 reputation)SSC Veteran (271 reputation)SSC Veteran (271 reputation)SSC Veteran (271 reputation)SSC Veteran (271 reputation)SSC Veteran (271 reputation)SSC Veteran (271 reputation)SSC Veteran (271 reputation)

Group: General Forum Members
Points: 271 Visits: 173
Hi Keith,
Thanks for the suggestions. I appreciate it.

And I apologize for the slow feedback and lack of it. I was on another project, putting out another fire. I have just come back to this today; who knows what Monday brings?:-D

Nevertheless, thank you very much for your help.
maximo121
maximo121
SSC Rookie
SSC Rookie (39 reputation)SSC Rookie (39 reputation)SSC Rookie (39 reputation)SSC Rookie (39 reputation)SSC Rookie (39 reputation)SSC Rookie (39 reputation)SSC Rookie (39 reputation)SSC Rookie (39 reputation)

Group: General Forum Members
Points: 39 Visits: 10
this process is important to keep the database working fine and is important compact and repair frequently as here.

Max
LawrenceStanl
LawrenceStanl
Grasshopper
Grasshopper (15 reputation)Grasshopper (15 reputation)Grasshopper (15 reputation)Grasshopper (15 reputation)Grasshopper (15 reputation)Grasshopper (15 reputation)Grasshopper (15 reputation)Grasshopper (15 reputation)

Group: General Forum Members
Points: 15 Visits: 1
When you restore an entire database, you replace a database file that is damaged, has data problems, or is missing altogether, with a backup of the entire database.

If the database file is missing, copy the backup to the location where the database should be.
IMPORTANT If other databases or programs have links to objects in the database that you are restoring, it is critical that you restore the database to the correct location. If you do not, links to the database objects will not work and will have to be re-created, such as by using the Linked Table Manager.

If the database file is damaged or has data problems, delete the damaged file and then replace the damaged file with the backup.

Or try:
eRepair Access is a powerful Access database recovery solution for damaged *.mdb and *.accdb files created in Access 2000 and above.

For more information: http://access.erepairtools.com/

And the similar question was discussed here: http://www.filerepairforum.com/forum/microsoft/microsoft-aa/access/314-ms-access-mdb-ldb-database-corrupted
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