Export table and restart from last table

Hello all,

Thank you in advance for reading my post and helping me..

Scenario:

I have 50 tables whose names are in a file export.sql, i use the below command to export all these tables one by one

cat export.sql|while read tn
      do
       echo "export to $tn.del of del select from $tn"
     done

Problem:

The problem is when this job stops some where in between working on these 50 tables, for ex on 24th table. When i restart the script, i would like the script to know the last worked table name and then continue from the next table so that i dont backup the table twice.

Please help me out and let me know if any questions

How does the full script looks like? How are you piping the info into sql? is it sql?

The problem is, your script doesn't know the last table the database successfully imported -- it only knows what ones it printed.

If these are long operations, then I wouldn't see any harm in running these operations individually instead of piping them all into one database call. That way you could tell when the database finished, by when the DBMS quits. You'd also get its return value, which is useful to check.

How to do this depends on what your code is, as ahmed101 said.

The above mentioned operation prints individual export commands into a different file which is run against the database.

But with this approach i am not having any control on restarting the job as it would start from beginning.

please let me know if you still have questions on this..thank you in advance

We require information from you. We don't know what DBMS utility you're using. What, exactly, do you type to run that output file against the database?

i am using db2 for this

  1. i have all the tables in a file export.sql
  2. i use the below script to print all the export statements to another file
cat export.sql|while read tn
      do
       echo "export to $tn.del of del select from $tn"
     done
  1. i run the final file with db2 -tvf filename through cron

Can't you either remove each table exported from that file or write each table exported to a log file to be eliminated from export.sql (e.g. grep -v ) for the next run?

Perhaps something like:

while read tn
do
        if ! db2 "export to $tn.del of del select from $tn"
        then
                echo "Couldn't export $tn"
                echo "Couldn't export $tn" >&2
                break
        fi

        echo "Exported $tn"
done < export.sql > logfile