简体   繁体   中英

How to backup mysql database on regular basis using php code

I want to backup mysql database on regular basis like weekly using php script. Is this possible if yes can you tell me the site or code over here. Thanks in advance.

A simple PHP function to do this job for us and we can call that function using Cron Job in regular time interval.

Ref : http://www.a2zwebhelp.com/mysql-database-backup-php

`

<?php

$connection = mysql_connect("localhost","uname","pswrd");
$qry="show databases";
$rs=mysql_query($qry); 
while ($row=mysql_fetch_array($rs,MYSQL_BOTH))
{
    if($row[Database]!="information_schema")
      {
        if($row[Database]!="mysql")
         {
                $fname1="/Your/Destination/Folder/".$row[Database].".sql.gz"; echo $fname1."<br>";
                    $efg   =@unlink($fname1);
                $command1 = "mysqldump --opt -uroot -proot -h localhost ".$row[Database]." | gzip>".$fname1;
            $rs_Sys1=system($command1);
            chmod($fname1,0777);

         }
     }
}


?>

` Run this program to get the sql backup and if you want to get the backup on a regular basis like daily/weekly, assign this program to cron (cron is a time-based job scheduler).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM