I have a pt-archiver job that runs on a cron schedule. It is meant to copy a subset of ID columns from table A and insert into table B, then delete from table A (pretty standard, I think). However, Both table A and B have a UNIQUE Key on the primary identifier (primary key is an auto-id; not talking about that). If the job ends or fails, the next run will fail early with a Duplicate Key error as it seems to be trying to reprocess the last batch where INSERTS into table B were already done but, apparently, deletes from table A were not.
What is the best practice here?