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!

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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);
?>

Link to comment
Share on other sites

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);
?>

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.