Reputation: 620
For a while now I've been trying to automate the backup of some databases I've got running in my localhost. I have a couple of personal apps running on my PC and I would like to back their db's continuously so as not to lose any of that info (because it's not online, so there's always the issue with my PC breaking down or a virus wiping everything out, etc.)
So I've been looking for a way to do this for some time now. I've continuously hit walls due to the fact that this is a local virtual server. But finally I seem to have found a way to do it.
It works perfectly at the output end. I mean, I wanted something that would output the dbs to my Dropbox, for instance, and this works... It outputs a file, alright, but the file is empty, which can only mean it's not able to retrieve the actual data. I've tried several things, including setting the exact path of the SQL data within my Wamp folder, but to no avail.
I'm rather stuck here. Maybe somebody could give me a hand. Thanks!
The PHP I'm using is simple enough, just an ´exec()´ command as you can see below:
exec('mysqldump --user='.$_SESSION['user'].' --password='.$_SESSION['password'].' --host=localhost myDatabase > C:\Users\Xavier\Dropbox\db_backups\file.sql');
Upvotes: 1
Views: 15623
Reputation: 620
OK! So it seems I was able to get it to work.
A little more research and I found this website: See the website
Basically, it told me what path to follow in order to run the mysqldump
on the Dbs in my Wamp server and everything was output as expected.
My case is rather specific and perhaps many people don't share this need, but this is the result:
exec('C:\wamp\bin\mysql\mysql5.6.12\bin\mysqldump --user='.$_SESSION['user'].' --password='.$_SESSION['password'].' --host=localhost myDatabase > C:\Users\Xavier\Dropbox\db_backups\file.sql');
By the way, thanks a lot to @MarcB and @mb14 for trying to help me out and posting their comments below!
Upvotes: 5