SSIS etl tables backup concept

  • Hello,

    I have a production database which is loaded regularly via SSIS packages.

    In the database there are etl (schema) tables which are loaded by every load with all the info, so that they can be used as a backup at some point.

    Now I want to have the full history of the etl tables only on my local server (which is a copy of the production) and to keep only the last three months on production.

    Do you have an idea how to create this SSIS?

    Thanks.

  • I'm not sure I'm fully understanding what you're attempting, but are there any datetime columns in your data you can use to extract out three months?

  • When you say three months, do you mean a rolling 93 days, or archive a month at the end of each month (i.e. have between 3 and 4 months on the PROD server).

    Why do you only want recent data on the PROD server. If it is a performance issue then you should be looking at server configuration and indexing. If it is space or security then you should be looking at partitioning the database and limiting access to the older partitions.

  • Hello Veteran,

    Thank you for the reply.

    First it is a space issue and also design issue.

    However what I need is to keep only the data from the last ~90 days.

  • So what we are looking at is a rolling delete process

    My preference (for codeability) would be a sproc in the database that takes two arguments Tablename to be deleted and Days to Keep

    The sproc would build a dynamic SQL statement to remove the records

    NOTE the code below has not been checked, it is symantec rather than syntactic.

    CREATE PROCEDURE dbo.uspDeleteOldData (@TableName nvarchar(50), @DaysToKeep int default = 90)

    AS

    DECLARE @SQL as nvarchar(max)

    SET @SQL = N'DELETE FROM ' + @TableName + ' WHERE CreateDate <= ''' + cast(DateAdd(days,(@DaysToKeep * -1), getdate()) as nvarchar)

    sp_executeSQL @SQL

    I would then build an SSIS package that simply has a list of SQL tasks that calls the sproc for each table you need to clean up.

    NOTE that you may end up with lots of sparsely populated index pages so you will need to clean up the database on a regular basis to remove the unused space.

  • NOTE the code below has not been checked, it is symantec rather than syntactic.

    I think you meant 'semantic', unless your solution is proposing an unorthodox anti-virus methodology 🙂

    If you haven't even tried to resolve your issue, please don't expect the hard-working volunteers here to waste their time providing links to answers which you could easily have found yourself.

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

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