Jump to content

Simple mysqldump cron script


Lodius2000

Recommended Posts

Hi guys... im trying to make a db backup script and I got this code from the intarwebs, and wouldnt you know, its not working

 

in produces a .gz file that when uncompressed is a blank file

 

whats wrong, i am betting its in the $command line but i dont really know what all that stuff means, other than the variables in there

 

<?php
//config.php contains all variables used in $command line, all of which are copy pasted from db_login.php
include ('../../dbbackups/config.php');
require ('../install/PEAR/DB.php');
require ('../../dbfiles/db_login.php');

$backupFile = '../../dbbackups/' . date("Y-m-d") . '.gz';
$command = "mysqldump --opt -h $dbhost -u $dbuser -p $dbpass $dbname | gzip > $backupFile";
system($command);

?> 

 

thanks for your help

Link to comment
https://forums.phpfreaks.com/topic/141166-simple-mysqldump-cron-script/
Share on other sites

When calling and external command from php you need to use the full path to the command.

 

If you have ssh access to your server login and run

 

which mysqldump 

 

to find the path. If you don't have ssh access contact your server provider. Edit the command to include the full path.

 

A common path is /usr/bin/mysqldump

 

Also I doubt you need the PEAR/DB.php file unless you put it there for a reason. 

do i even need to connect to my db, or does mysqldump do that for me? i mean it seems odd that i am putting in the same usn pw and hostspecs twice?

 

You do not. But what you do need is the full path to mysqldump and the apache or whatever user php runs as needs write permissions on the destination folder.

 

The apache error logs file should tell you what the problem is.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.