| | |
PHP script to backup mysql
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Thread Solved |
•
•
Join Date: Apr 2008
Posts: 507
Reputation:
Solved Threads: 0
Hi,
I am trying to backup one of my Mysql database with a PHP script.
Executed code works fine in Linux terminal (toy-10-09-2009-16:15:49.sql) but when i run this PHP script it doesn't work. No error too.
What do you think i miss?
Thanks
I am trying to backup one of my Mysql database with a PHP script.
PHP Syntax (Toggle Plain Text)
<?php $host="localhost"; $database="toy"; $username="root"; $password=""; $connection=mysql_connect($host, $username, $password); if(!$connection) { die("ERROR: Couldn't connect to the server."); } else { $dbSelect=mysql_select_db($database); if(!$dbSelect) { die("ERROR: Couldn't select the database."); } else { $mysqldumpPath="/usr/bin/mysqldump"; $backupFileName = "Desktop/toy-`date +%d-%m-%Y-%H:%M:%S`.sql"; $createBackup = $mysqldumpPath." -u ".$username." -h ".$host." ".$database." > ".$backupFileName; exec($createBackup); } } ?>
What do you think i miss?
Thanks
Last edited by veledrom; Sep 10th, 2009 at 12:34 pm. Reason: .
On this line:
You probably are going to need the absolute path to where the file needs to be stored.
PHP Syntax (Toggle Plain Text)
$backupFileName = "Desktop/toy-`date +%d-%m-%Y-%H:%M:%S`.sql";
Google is your friend.
Use [code] tags.
If you have found a solution to your problem, please mark the thread as SOLVED.
Use [code] tags.
If you have found a solution to your problem, please mark the thread as SOLVED.
No error. That's because you didn't echo the exec function. Line 18 should be as follows:
php Syntax (Toggle Plain Text)
echo exec($createBackup);
Try not to bump 10 year old threads as it can be really annoying.
http://syntax.cwarn23.net/
My favourite PC. - Oopy Doopy Do 2U2!
http://syntax.cwarn23.net/
Smilies: ^_* +_+ v_v -_- *~*` My favourite PC. - Oopy Doopy Do 2U2!
•
•
Join Date: Apr 2008
Posts: 507
Reputation:
Solved Threads: 0
Still doesn't work. Also no error for
I changed the path to
As i said before, it works fine in Ubuntu terminal. I also, tar it in the terminal without any problem with same path.
Thanks
echo exec($createBackup);.I changed the path to
/usr/bin/mysqldump -u root -h localhost toy > /var/www/toy/toy-11-09-2009_10:03:41.sql but, still doesn't work in the script. As i said before, it works fine in Ubuntu terminal. I also, tar it in the terminal without any problem with same path.
Thanks
In Ubuntu. ok. I found this problem when I first got a Virtual Private Server. The server had a different file structure than what my Ubuntu did. So try to browse around your server to make sure those are the locations for your servers Operating System. There seems to be two mains sorts of systems of sorting files from my experience.
Try not to bump 10 year old threads as it can be really annoying.
http://syntax.cwarn23.net/
My favourite PC. - Oopy Doopy Do 2U2!
http://syntax.cwarn23.net/
Smilies: ^_* +_+ v_v -_- *~*` My favourite PC. - Oopy Doopy Do 2U2!
•
•
•
•
Still doesn't work. Also no error forecho exec($createBackup);.
I changed the path to/usr/bin/mysqldump -u root -h localhost toy > /var/www/toy/toy-11-09-2009_10:03:41.sqlbut, still doesn't work in the script.
As i said before, it works fine in Ubuntu terminal. I also, tar it in the terminal without any problem with same path.
Thanks
Does your root account on mysql have no password? Just wondering...
www.fijiwebdesign.com - web design and development and fun
Cpanel Email - Let users Register email accounts on your website upon registration
Ajax Chat - Fully browser based chat!
Cpanel Email - Let users Register email accounts on your website upon registration
Ajax Chat - Fully browser based chat!
•
•
•
•
Hi digital,
I don't know how to check if PHP has R+W privilages !!!
No password for MySQL. I didn't set it.
Thanks
eg:
PHP Syntax (Toggle Plain Text)
$result = file_put_contents('/var/www/toy/test.txt', 'hi'); var_dump($result);
www.fijiwebdesign.com - web design and development and fun
Cpanel Email - Let users Register email accounts on your website upon registration
Ajax Chat - Fully browser based chat!
Cpanel Email - Let users Register email accounts on your website upon registration
Ajax Chat - Fully browser based chat!
•
•
Join Date: Apr 2008
Posts: 507
Reputation:
Solved Threads: 0
I have this info in 'User Settings'
Name-------Login name--------Home directory
veledrom ubuntu /home/ubuntu (this is active-bold and black coloured)
root root /root (this looks inactive-grey coloured)
This is what i did before.
ubuntu@ubuntu:~$ sudo chown -hR root /var/www/toy
I realise that i use root to login to mysql but in the terminal it shown ubuntu. Is ubuntu still root?
What can i do now? I bet it is something to do with users and permitions as you said, digital
Name-------Login name--------Home directory
veledrom ubuntu /home/ubuntu (this is active-bold and black coloured)
root root /root (this looks inactive-grey coloured)
This is what i did before.
ubuntu@ubuntu:~$ sudo chown -hR root /var/www/toy
I realise that i use root to login to mysql but in the terminal it shown ubuntu. Is ubuntu still root?
What can i do now? I bet it is something to do with users and permitions as you said, digital
![]() |
Similar Threads
- Help with php script to export mysql data and import data (PHP)
- question about connecting odbc to sql through php script (PHP)
- Please school me in PHP script installation. (MySQL)
- how to make member expire after so many days with php script (PHP)
- How many clients can access a PHP script at a time from a MySQL server? (MySQL)
- How many clients can access a PHP script at a time? (PHP)
Other Threads in the PHP Forum
- Previous Thread: uploading files with php
- Next Thread: PHP Editor Like Wordpress
| Thread Tools | Search this Thread |
Tag cloud for PHP
.htaccess access ajax apache api array beginner binary broken cakephp checkbox class cms code codingproblem cron curl database date directory display download dynamic echo email error file files folder form forms function functions google href htaccess html image include insert integration ip java javascript joomla limit link login loop mail memmory menu methods mlm mod_rewrite multiple mysql oop parse paypal pdf php problem query radio random recursion regex remote script search select send server sessions sms snippet soap source space speed sql static structure syntax system table tutorial up-to-date update upload url validation validator variable video web wordpress xml youtube






