May 1, 2013 asvignesh 2Comment

In the last post i explained about taking the MySQL backup using php code , This post explains to take the backup of your MySQL database using the passthru function ( passthru documentation )

The passthru() function is similar to the exec() function in that it executes a command. This function should be used in place of exec() or system() when the output from the Unix command is binary data which needs to be passed directly back to the browser

$datestamp = date("Y-m-d"); // Present date to append in the filename for the identification
$dbuser = ""; // Database username
$dbpwd = ""; // Database password
$dbname = ""; // Database name. Use --all-databases if you have more than one
$filename= "backup-$datestamp.sql.gz"; // The name (and optionally path) of the dump file
$command = "mysqldump -u $dbuser --password=$dbpwd $dbname | gzip > $filename";
$result = passthru($command);

The SQL dump will generate and store in the default directory , You can set the full path in the $filename , Note this will work only in the locally hosted database server

6+ years of experience in building data protection, copy data management and storage management applications, automation software and plugins for private and public clouds

Disclaimer :

This is a personal weblog. The opinions expressed here represent my own and not those of my employer. my thoughts and opinions change from time to timeā€¦ This weblog is intended to provide a semi-permanent point in time snapshot and manifestation of the various memes running around my brain, and as such any thoughts and opinions expressed within out-of-date posts may not the same, nor even similar, to those I may hold today.

2 thoughts on “Take MySQL backup using php passthru function

  1. Everyone loves what you guys are usually up too.

    This type of clever work and reporting! Keep up
    the very good works guys I’ve added you guys to blogroll.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.