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');Answer1:
OK! So it seems I was able to get it to work.
A little more research and I found this website: <a href="http://snippetsofcode.wordpress.com/2011/08/02/howto-dump-mysql-database-on-wamp/#respond" rel="nofollow">See the website</a>
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!