Jump to content

Backing up the Database PHP ??


radiations3

Recommended Posts

yes, it's possible, and yes, I back up my databases.

what I normally do is tar -czf the entire mysql folder.

I actually have a cron tab set up to do this every day at midnight.

 

you can do the same with php, or you could dump the database to a csv file.

Link to comment
Share on other sites

yes, it's possible, and yes, I back up my databases.

what I normally do is tar -czf the entire mysql folder.

I actually have a cron tab set up to do this every day at midnight.

 

you can do the same with php, or you could dump the database to a csv file.

 

I got this code :

 

<?php
include 'config.php';
include 'opendb.php';

$dbuser = "root";
$dbpass = "";
$dbhost = "localhost";
$dbname = "bakery";

$backupFile = $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';
?>

 

But when i run it i got following error messages kindly help to resolve them...

 

 

Warning: include(config.php) [function.include]: failed to open stream: No such file or directory in D:\DBMS\DB.php on line 2

 

Warning: include() [function.include]: Failed opening 'config.php' for inclusion (include_path='.;C:\php\pear') in D:\DBMS\DB.php on line 2

 

Warning: include(opendb.php) [function.include]: failed to open stream: No such file or directory in D:\DBMS\DB.php on line 3

 

Warning: include() [function.include]: Failed opening 'opendb.php' for inclusion (include_path='.;C:\php\pear') in D:\DBMS\DB.php on line 3

 

Warning: include(closedb.php) [function.include]: failed to open stream: No such file or directory in D:\DBMS\DB.php on line 14

 

Warning: include() [function.include]: Failed opening 'closedb.php' for inclusion (include_path='.;C:\php\pear') in D:\DBMS\DB.php on line 14

Link to comment
Share on other sites

because that script relies on 3 external files that you don't seem to have:

config.php, opendb.php and closedb.php

 

the error says: "No such file or directory"

 

I corrected it but now i am not able to see that where my backup file is getting saved i am very close to solve this problem kindly help

 

my current code:

 

<?php
//include 'config.php';
//include 'opendb.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 > $backupFile";
system($command);
//include 'closedb.php';
mysql_close($conn);
?>

Link to comment
Share on other sites

this is all you need: (except you need to specify the path to mysqldump correctly)

 

$u = 'username';
$p = 'password';
$db = 'databasename';
system("/Applications/MAMP/Library/bin/mysqldump -u$u -p$p $db  > test.sql");

 

Did it what you told but a file of 0byte got saved named as test.sql

Link to comment
Share on other sites

the you didn't do it properly. that EXACT same script worked for me. read my previous post again and locate where you mysqldump is, then replace the path with the correct one.

 

this: /Applications/MAMP/Library/bin/mysqldump will only work if you're on a Mac using Mamp. You need to specify YOUR path.

Link to comment
Share on other sites

the you didn't do it properly. that EXACT same script worked for me. read my previous post again and locate where you mysqldump is, then replace the path with the correct one.

 

this: /Applications/MAMP/Library/bin/mysqldump will only work if you're on a Mac using Mamp. You need to specify YOUR path.

 

How can i specify my path?? So that i'll use the right path to process my code properly???

Link to comment
Share on other sites

Well thanks all for helping me out i'll try to google it to solve my issue....

 

I gave you the answer. If you can't find the path to your mysqldump, google won't help you much.

 

Actually i am a newbie so i am not very good at it ... so i am trying to find some other to backup the database you really helped me out at your level best but due to my lack of knowledge i am not able to solve my issue....

Thank You for the help!!!

Link to comment
Share on other sites

you found this path:

C:\Program Files (x86)\EasyPHP-5.3.6.0\mysql\bin\mysqldump.exe

then you used this one:

C:\Program Files (x86)\EasyPHP-5.3.6.0\mysql\bin\mysqldump

 

See what's wrong there?

 

I TRIED BOTH ABOVE MENTIONED PATH AND I AM NOT GETTING WHY THE BACKUP IS NOT CREATING :(

IF YOU HAVE ANY PHP FILE FOR BACKING UP THE DATABASE THEN KINDLY SHARE IT I'LL BE VERY THANKFUL TO YOU

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.