Jump to content

Backing up the Database PHP ??


radiations3

Recommended Posts

OKAY JUST TELL ME ONE LAST THING

THE WEB HOSTING SERVICES I AM USING IS SETUP TO LINUX

SO IF YOU GIVE ME YOUR METHOD OF BACKING UP DATABASE CAN I USE IT ON MY ONLINE SERVER..

 

JUST GUIDE ME WHICH METHOD I MUST USE TO BACKUP MY DATABASE IN YOUR POINT OF VIEW SO I'LL START WORKING ON IT AS PER YOUR GUIDANCE???...

 

THANKS!

it's not really the same thing. I set up my own servers, so I actually have root access to the entire machine.

 

First you need to check if you have any way of setting up cron tabs (in cpanel, or whatever other administration system they provide)

 

then you need to know exactly where your database folders are... then all you need is to set up a cron tab with something like:

 

tar -czf /path_to_BACKUP_FOLDER/filename_`date +%d-%m-%Y`.tgz /path_to_MYSQL_FOLDER

 

and schedule it to whatever time of the day / days of the week you want

Can anyone tell what is wrong with the following code because when i run it then it saves the file of 0byte and doesnot create the backup  of my database??

 

<?php
$dbuser = "root";
$dbpass = "";
$dbhost = "localhost";
$dbname = "bakery";
$conn = mysql_connect($dbhost, $dbuser, $dbpass)  or die ('Error connecting to mysql');
mysql_select_db($dbname);

$backupFile = $dbname . date("Y-m-d-H-i-s") . '.gz';
$command = "mysqldump --opt -h $dbhost -u $dbuser -p $dbpass $dbname | gzip > upload/$backupFile";
system($command);
//include 'closedb.php';
mysql_close($conn);
?>

try this.

 

<?php
$dbuser = "root";
$dbpass = "";
$dbhost = "localhost";
$dbname = "bakery";
$conn = mysql_connect($dbhost, $dbuser, $dbpass)  or die ('Error connecting to mysql');
mysql_select_db($dbname);
if($conn){
   $backupFile = 'upload/' . $dbname . date("Y-m-d-H-i-s") . '.gz';
   $command = "mysqldump --opt -h $dbhost -u $dbuser -p $dbpass $dbname | gzip > $backupFile";
   system($command);
   //include 'closedb.php';
}else{

print "invalid connection";

}
mysql_close($conn);
?>

 

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.