Roots Discourse

Permission error on msql dump when using wp-cli aliases

Hi,

When using this script
sync-dev-to-prod-FOR-REAL.sh
Referenced here: Leveraging WP-CLI Aliases in Your WordPress Development Workflow

When the alias tries to save a backup (just-in-case.sql) I have a permissions problem. Any idea how to fix this?

In my test, I was actually using a staging alias like this:

   @staging:
      ssh: admin@staging.example.com/srv/www/example.com/current

mysqldump: Can’t create/write to file ‘just-in-case.sql’ (Errcode: 13 “Permission denied”)

Where does your script currently reside? (In a Trellis/Bedrock setup, it should go in the ‘site’ folder).

And where are you running the script? You should be running it from the same directory where the script exists (again the ‘site’ folder if you’re using Bedrock).

1 Like

I put my .sh script in “trellis/bin” because that’s where the other .sh script was. Not sure where to put it.

I’m running the script from within the “site” folder. The aliases (wp-cli.yml) are in “site”.

Can you try putting it in the ‘site’ folder and reporting back?

same permissions error
mysqldump: Can’t create/write to file ‘just-in-case.sql’ (Errcode: 13 “Permission denied”)

This works now.

What I did.

changed the user in the alias to “web”:

From

 @staging:
      ssh: admin@staging.example.com/srv/www/example.com/current

To

 @staging:
      ssh: web@staging.domain.com/srv/www/domain.com/current

Removed “->” (not sure if this is needed, couldn’t find it in the wp-cli documentation)

From

wp @development db export - > sql-dump-development.sql

To

wp @development db export sql-dump-development.sql


Added a timestamp to the backup (unrelated to fix).

wp @staging db export just-in-case-$(date +%Y-%m-%d_%T).sql


Removed the “sql-dump-development.sql” file at the end (unrelated to fix).

ssh web@staging.example.com 'rm /srv/www/example.com/current/sql-dump-development.sql'

Complete version

read -r -p "Would you really like to reset THE STAGING DATABASE and send up the latest from dev? [y/N] " response
if [[ $response =~ ^([yY][eE][sS]|[yY])$ ]]
then
    wp @development db export sql-dump-development.sql
    scp sql-dump-development.sql web@staging.example.com:/srv/www/example.com/current

    wp @staging db export just-in-case-$(date +%Y-%m-%d_%T).sql
    wp @staging db reset --yes

    wp @staging db import sql-dump-development.sql
    wp @staging search-replace http://example.dev https://staging.example.com
    scp -r web/app/uploads/ web@staging.example.com:/srv/www/example.com/shared
    ssh vagrant@example.dev 'rm /srv/www/example.com/current/sql-dump-development.sql'
    ssh web@staging.example.com 'rm /srv/www/example.com/current/sql-dump-development.sql'
else
    exit 0
fi

I would appreciate it if someone more knowledgeable than me can look this over and let me know if anything is totally wacko.

2 Likes

I’ve been looking about to make myself a similar script. Have you figured it out yet?