Copies of backups.

  • 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/20141/15/20141/16/,1/17,1/20 3

    1/21/20141/16/20141/17,1/20,1/21 3

    1/22/20141/17/20141/20,1/21,1/22 3

    1/23/2014No file1/20,1/21,1/22,1/23 4

    1/24/2014No file1/20,1/21,1/22,1/23,1/245

    1/25/20141/20/20141/21,1/22,1/23,1/244

    1/26/20141/21/20141/22,1/23,1/24 3

    1/27/20141/22/20141/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.

  • 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

    ,@endDatedate

    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[/url]

  • 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.

  • this process is important to keep the database working fine and is important compact and repair frequently as here.

    Max

  • 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/[/url]

    And the similar question was discussed here: http://www.filerepairforum.com/forum/microsoft/microsoft-aa/access/314-ms-access-mdb-ldb-database-corrupted

Viewing 5 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply