简体   繁体   中英

Table data backup through unix script

I m creating a unix script for our prod enviornment. Requirement is to create a backup of table (not the entire table) few rows. Perform some operation on table(update and delete). At end delete new data and restore back. Problem is how to take backup in prod enviornment. I cant have temp table there.

Script it something like this.

spool below query
select 'insert into <tablename> values ( ' || col_1 || ','|| col_2 || ','|| col_3 .. so on
from <tablename> <where condition>  --- generate backup

perform operation on table <delete/update>

delete new values 

Restore backup executing spool file

I find this appoarch kind of tedious, is there any better way to accomplish this task?

Note :- This script will be executed in prod where I dont have access to create table. Can perform only update/delete on given table.

Database - 10g

The less tedious way is to use the temporary table approach unfortunately, preferably in a different schema of course. Keeping all the operations and data in the database will be faster and more simple to code, and more reliable.

Alternatively you could use FLASHBACK TABLE if this is not a lengthy timescale and no other changes occur on the data. If other changes do occur then it would only be slightly more complex to use a flashback query clause to restore the old data.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM