# Permission error on msql dump when using wp-cli aliases

**URL:** https://discourse.roots.io/t/permission-error-on-msql-dump-when-using-wp-cli-aliases/8426
**Category:** archived 🗄
**Created:** 2016-12-30T23:09:06Z
**Posts:** 9

## Post 1 by @ericgauvin — 2016-12-30T23:09:06Z

Hi,

When using this script  
sync-dev-to-prod-FOR-REAL.sh  
Referenced here: [Leveraging WP-CLI Aliases in Your WordPress Development Workflow - #2 by benword](https://discourse.roots.io/t/leveraging-wp-cli-aliases-in-your-wordpress-development-workflow/8414/2)

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”)

---

## Post 2 by @anon56740962 — 2016-12-30T23:30:33Z

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).

---

## Post 3 by @ericgauvin — 2016-12-30T23:33:38Z

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”.

---

## Post 4 by @ben — 2016-12-31T00:20:57Z

> [@ericgauvin](#):
>
> Not sure where to put it.

> [@cedarstay](#):
>
> it should go in the ‘site’ folder

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

---

## Post 5 by @ericgauvin — 2016-12-31T00:40:23Z

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

---

## Post 7 by @ericgauvin — 2016-12-31T02:24:37Z

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.

---

## Post 8 by @david-treblig — 2017-08-17T20:06:06Z

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

---

## Post 9 by @ben — 2022-02-26T03:19:45Z


