I’ve been working on a CMS and wanted to add a backup/restore function. I want it to backup a saved entry every other time it is edited so that if a client makes a change they are unhappy with or screws something up they can go back and choose a previous state to restore from.
The problem I’m having is trying to wrap my head around the concept of coding this functionality. I have created a new table called “backup” with the fields “ID, date, time, pageName, and pageContent” but going on from there I find myself stuck.
Would I add on to my edit script a new query that saves a duplicate to the backup table? And how could I get it to only backup every few saved edits?
Here I have my save edit query, if it helps any. Thanks in advance! 🙂
<?php
$_POST['entry'] = mysql_real_escape_string($_POST['entry']);
$sql="update pageEntry set entry=\"$_POST[entry]\", pageName=\"$_POST[pageName]\" where id=\"$_POST[id]\"";
$result=mysql_query($sql)or die('Bad Query');
echo "<div id='edit2'>The file has been uploaded, and your information has been added to the directory<br /></div>";
?>
Version control at the table level is usually done by adding a
versioncolumn to your existing table. So if you had apoststable you would add a version column with a simple int or date value. Every time a post is edited a new record is inserted and the version number bumped. You can reference this version number in another table or have an additionalactivefield to denote which post is the latest/active.If you’re talking about rolling back the database I would use the
mysqldumpcommand to dump andmysqlto restore.