Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Copies of backups. Expand / Collapse
Author
Message
Posted Wednesday, January 22, 2014 11:27 AM
Valued Member

Valued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued Member

Group: General Forum Members
Last Login: Yesterday @ 12:24 PM
Points: 57, Visits: 169
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.
Post #1533776
Posted Wednesday, January 22, 2014 1:31 PM


Mr or Mrs. 500

Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500

Group: General Forum Members
Last Login: 2 days ago @ 10:53 AM
Points: 597, Visits: 937
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
Post #1533818
Posted Friday, February 14, 2014 2:20 PM
Valued Member

Valued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued Member

Group: General Forum Members
Last Login: Yesterday @ 12:24 PM
Points: 57, Visits: 169
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?

Nevertheless, thank you very much for your help.

Post #1541771
Posted Thursday, August 21, 2014 11:27 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Tuesday, August 26, 2014 12:18 PM
Points: 4, Visits: 6
this process is important to keep the database working fine and is important compact and repair frequently as here.

AccessFIX
Post #1605938
Posted Tuesday, October 14, 2014 11:12 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Tuesday, October 14, 2014 11:11 AM
Points: 2, 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
Post #1625543
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse