What is a good way to track changes in a staging DB and then push accepted data onto the main DB?
My client needs a script or any solution: if he has two database, one staging DB in which he tests his data on the test portal and if he find it appropriate he can use those changes on the main DB, which is displayed on the live site. For this he needs the solution to record or track all updates/deletes/inserts, so that he can do the same in main DB if found appropriate.
NOTE: we have only one server, no separate server, hence binary log replication doesn't seems to be working for my case.
Assuming that both test and production databases can evolve independently during the test period, I'd say a good starting point for thinking about a solution would be to activate query logging on the test database then, at the end of the day, extract ALTER
, CREATE
, DROP
, INSERT
, UPDATE
, DELETE
etc. statements from the test database query log file and simply try to play those statements back on the production database, possibly separating DDL and DML (with the DML in one transaction.)
If any of your tables have auto-increment columns used as foreign keys in other tables, use an AFTER
trigger to capture actual auto-increment values for INSERT
and UPDATE
statements and write a corresponding SQL statement to a separate file for production playback; you may still use query logging to capture DDL statements (and DELETE
s, although they can be captured via trigger too.)
Unlike binary logs, query logs (or equivalent logs produced from a trigger) are clear-text and allow you to further manually tweak queries to resolve any potential conflicts or divergences between the production and test systems.