1

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');
8
  • does whatever user php is running under have the rights to write into your home directory? Commented Nov 14, 2013 at 22:01
  • Have you sought about setting up a replication ? Commented Nov 14, 2013 at 22:07
  • @MarcB Yes, I always run as Admin. Am the only one using the PC. Commented Nov 14, 2013 at 22:09
  • @mb14 I'm not sure what you mean by "setting up a replication." I'm a self-taught coder, so basically still rather an amateur on many things. I'm afraid this is one of them. I don't know what you're referring to. Though I'm looking it up online as I write this! Commented Nov 14, 2013 at 22:10
  • google mysql replication => dev.mysql.com/doc/refman/5.0/en/replication.html. It's a way to synchronize in realtime 2 database, a master and slave, which is pretty much what you are trying to achieve Commented Nov 14, 2013 at 22:12

1 Answer 1

5

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!

Sign up to request clarification or add additional context in comments.

1 Comment

Perfect answer it saves my day

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.