Re: restore mysql DB every hour
Jerry Stuckle wrote:
> CNN_news wrote:
>> I have a CMS driven website that uses MySQL as is database.
>>
>> I want to create a demo site that anyone can edit but that resets its
>> contents every hour so changes are not permanent.
>>
>> How can I do this?
>>
>> Thanks.
>>
>
> Build the database to the point where you want it restored. Back it up
> and create a cron job to restore it once an hour.
>
> BTW, I recommend stopping MySQL while the restore is being performed.
Nah. Make up tables that represent the database in the desired initial
state. Then, every hour, make new copies of those tables. Then use
ALTER TABLE with RENAME to rename the current tables to "old" versions,
and the new copies to the current tables. Then delete the old versions.
Multiple renames done in one ALTER TABLE are atomic, so you can do this
with activity in the database. It's all interlocked and you don't have to
shut down.
Or make all the databases InnoDB databases, and in one transaction,
set them back to the desired ground state. When you commit the transaction,
all the changes happen as an atomic operation, without interfering with
anything in progress.
John Nagle
|