Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Backup only data older than 1 year

Status
Not open for further replies.

ktai

IS-IT--Management
Jan 11, 2005
22
US
Does anyone know if there's a way to backup only data older than 1 year. What I am trying to do is first backup data older than 1 year and then purge that data from the database. I only want 1 year of data in the database, so I would probably run the backup/purge operation monthly.

Thanks for any help or suggestions!
 
You will have to write your own script to select the data out of each table into tables in another database. Then you can backup that database and remove the data from the other database.

- Paul
10qkyfp.gif

- If at first you don't succeed, find out if the loser gets anything.
 
Thanks, Paul. I probably should have mentioned that there are over 100 tables in the database. Do I have to manually put the name of each table into my script, or is there a way to simplify the proccess?

Thanks again.
 
Here is a quick way to create a copy of a table without any data.
Code:
SELECT * INTO <new_table_name>
FROM <old_table>
WHERE 1=2
[code]

I would create a new database.
Then run this in your current database.
It will create a script that will create your tables for you.
[code]
SELECT 'SELECT * INTO '+ name+'_bak FROM <db_name>.dbo.'+ name + ' WHERE 1=2'
FROM sysobjects
WHERE xtype = 'U'
[code]
Then you will need to write scripts to select data older than 1 year and populate your tables in the new database.
You can then back it up and remove the old data from your prod db.

- Paul  [img]http://i19.tinypic.com/10qkyfp.gif[/img]
- If at first you don't succeed, find out if the loser gets anything.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top