# Issue exporting a database using wp-cli from local development to remote staging server

**URL:** https://discourse.roots.io/t/issue-exporting-a-database-using-wp-cli-from-local-development-to-remote-staging-server/8811
**Category:** archived 🗄
**Created:** 2017-02-14T05:48:15Z
**Posts:** 15
**Showing post:** 4 of 15

## Post 4 by @nathobson — 2017-02-14T13:45:02Z

I’ve been playing with WP-CLI aliases as per: [Leveraging WP-CLI Aliases in Your WordPress Development Workflow](https://discourse.roots.io/t/leveraging-wp-cli-aliases-in-your-wordpress-development-workflow/8414). It’s great being able to run WP-CLI commands on remote servers and within vagrant right from the local `site` directory.

I also found the shell script @ben posted up made loads of sense. I tweaked it a bit for my liking and I use it for pushing the database and uploads from dev up to staging:

```
read -r -p "Would you really like to overwrite the staging database with 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.sql
    wp @staging db reset --yes

    wp @staging db import sql-dump-development.sql
    wp @staging search-replace https://example.dev https://staging.example.com

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

    read -r -p "Did everything run smoothly? Remove the temp backup sql file? [y/N] " response
    if [[$response =~ ^([yY][eE][sS]|[yY])$ ]]
    then
        ssh web@staging.example.com 'rm /srv/www/example.com/current/just-in-case.sql'
    fi

    read -r -p "Sync uploads from dev to staging? [y/N] " response
    if [[$response =~ ^([yY][eE][sS]|[yY])$ ]]
    then
        scp -r web/app/uploads/ web@staging.example.com:/srv/www/example.com/shared
    fi
else
    exit 0
fi
```

Could be improved I’m sure but works for me at the moment!

---

_[View the full topic](https://discourse.roots.io/t/issue-exporting-a-database-using-wp-cli-from-local-development-to-remote-staging-server/8811)._
