0

I'm trying to do a php script to backup my database. Here's what I've tried so far :

$command = "mysqldump -u [username] -p [password] [databasename] | gzip > db.sql.gz";
$this->output = system($command);
  • How do I get the password and username from databases.yml ?

  • How can I do a script that sends me the backup file, instead of saving it on the server (à la phpmyadmin) ?

1 Answer 1

2

You can create a symfony task. If you pass in an environment (i.e. dev, prod) or connection you get access to the Doctrine connection manager and create a connection. You can use that connection to make a database dump or get the connection details from the connection manager.

You can use the doctrine insert sql task as template for your task. I've done similar in the past.

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

7 Comments

Nice suggestion, but I'd like to be able to do it from everywhere, without having to log in to the server via ssh
Your solution above will still require you to ssh into the server. The only way to do it without ssh'ing into the server is to trigger it from the browser. You can trigger symfony task from in side your action by instantiating the task class. This is exactly what the cli app does.
I'll look into doing that in the action
Yeah, any symfony cli task can be executed from an action. This has the added bonus of making your code reusable and testable.
What about the second part of my question, the sending of the file ?
|

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.