ninedoors Posted March 14, 2009 Share Posted March 14, 2009 It there a way that I can backup just specific tables in a database instead of the whole database. Some of the tables I have don't changed to often and some are updated daily. So I would like to backup just those tables daily and then the ones that are updated not so often weekly. Is this possible. Here is what I am using right now: <?php $datestamp = date("Y-m-d"); // Current date to append to filename of backup file in format of YYYY-MM-DD /* CONFIGURE THE FOLLOWING SEVEN VARIABLES TO MATCH YOUR SETUP */ $dbuser = "*******"; // Database username $dbpwd = "*******"; // Database password $dbname = "********"; // Database name. Use --all-databases if you have more than one $filename= "/home/*******/backup_bmhl-$datestamp.sql.gz"; // The name (and optionally path) of the dump file $to = "*******@hotmail.com"; // Email address to send dump file to $from = "[email protected]"; // Email address message will show as coming from. $subject = "MySQL backup file - ". $dbname; // Subject of email $command = "mysqldump -u $dbuser --password=$dbpwd $dbname | gzip > $filename"; $result = passthru($command); $attachmentname = array_pop(explode("/", $filename)); // If a path was included, strip it out for the attachment name $message = "Compressed database backup file $attachmentname attached."; $mime_boundary = "<<<:" . md5(time()); $data = chunk_split(base64_encode(implode("", file($filename)))); $headers = "From: $from\r\n"; $headers .= "MIME-Version: 1.0\r\n"; $headers .= "Content-type: multipart/mixed;\r\n"; $headers .= " boundary=\"".$mime_boundary."\"\r\n"; $content = "This is a multi-part message in MIME format.\r\n\r\n"; $content.= "--".$mime_boundary."\r\n"; $content.= "Content-Type: text/plain; charset=\"iso-8859-1\"\r\n"; $content.= "Content-Transfer-Encoding: 7bit\r\n\r\n"; $content.= $message."\r\n"; $content.= "--".$mime_boundary."\r\n"; $content.= "Content-Disposition: attachment;\r\n"; $content.= "Content-Type: Application/Octet-Stream; name=\"$attachmentname\"\r\n"; $content.= "Content-Transfer-Encoding: base64\r\n\r\n"; $content.= $data."\r\n"; $content.= "--" . $mime_boundary . "\r\n"; mail($to, $subject, $content, $headers); unlink($filename); //delete the backup file from the server ?> If I need to do this a different way that would be fine. I would like to run the scripts from a cron though if possible. Thanks for th help. Nick Link to comment https://forums.phpfreaks.com/topic/149419-backing-up-specific-table-in-a-database/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.