Using the "jalogut/magento2-deployer-plus" I am unable to do a DB backup using the Magerun command. It throws an error where it shows the app/etc/env.php is not accessible. Even though i am pretty sure the control is reaching the project root from the deployer file.

enter image description here

2 Answers 2


I found where the issue was and that the control of the server has to be moved to magento root to execute the magerun command properly. So i had to cd into the root and then execute the command. The snippet is as follows:

    //Daily Db backup and deletion
task('db-backup', function () {
    run('if [ ! -d "{{deploy_path}}/db_backup" ]; then mkdir {{deploy_path}}/db_backup; fi');
    run('cd {{deploy_path}}/public_html && n98-magerun2 db:dump --compression="gzip" -f > {{deploy_path}}/db_backup/backup_$(date +%Y-%m-%d).sql.gz');
    run('find {{deploy_path}}/db_backup -type f -name "backup_*.sql.gz" -mtime +14 -delete');

Yes, it is possible to run the magerun db:dump command from a deployer.php file.

To do this, you can use the runLocally method provided by Deployer to run a local command on your machine. Here's an example code snippet that shows how to do it:

// Load the Deployer recipes
require 'recipe/common.php';

// Define a task to run the Magerun db:dump command
task('magento:backup', function () {
    // Run the Magerun db:dump command locally
    runLocally('magerun db:dump --add-time --compression="gzip"');

// Define a deployment task that depends on the backup task
task('deploy', [
    // other deployment tasks here

In this example, we define a magento:backup task that runs the magerun db:dump command using the runLocally method. We then define a deploy task that depends on the magento:backup task, so that the backup is performed before the deployment.

Note that you may need to modify the command arguments to suit your specific needs. Also, make sure that the magerun command is available on your local machine and that the path to the command is included in your system's PATH environment variable

  • Thank you, in a way the runLocally was helpful in moving me in the right direction.
    – Arjun B
    Commented Apr 10, 2023 at 12:54

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.