(Reading the comments, it seems that you're trying to create a way to easily and reliably synchronize your production database to your staging site. Perhaps you could update the question to make this more clear.)
This is a common problem and having a tool to do this reliably is really beneficial. I have written my own bash script to do it and this is the basic process you should be trying to replicate:
- Dump the production database to a gzip tarball
- Download the dumped tarball to your staging server
- Drop and recreate the staging DB
- Import the production dump into the staging DB
- Adjust any configuration as appropriate for your staging server (mainly changes in core_config_data such as web/unsecure/base_url and web/secure/base_url etc)
I would suggest as a first step to get this down to a set of commands that you can reliably run to give you the desired result. Then once you have the process refined you can think about automating it with a simple script.
The tool that is really going to help you here is n98-magerun which is a priceless CLI tool for the Magento developer.
Breaking down the steps above into n98-magerun commands:
1) Dump the production database to a gzip tarball
On your production server:
n98-magerun db:dump -c "gzip" ~/latest-production-db.sql.gz;
Consider also using the --strip
option to remove sensitive data such as customer and order records. Depends on your use-case. See n98-magerun docs for Stripped Database Dumps.
2) Download the dumped tarball to your staging server
On your staging server:
Use rsync or scp or whatever CLI tool is most convenient or familiar to download the tarball created above.
Example using scp:
scp user@production:~/latest-production-db.sql.gz ~/latest-production-db.sql.gz
3) Drop and recreate the staging DB
On your staging server:
n98-magerun db:drop && n98-magerun db:create
4) Import the production dump into the staging DB
On your staging server:
n98-magerun db:import -c "gzip" ~/latest-production-db.sql.gz
5) Adjust any configuration as appropriate for your staging server
On your staging server:
n98-magerun config:set web/secure/base_url https://staging.domain.tld/
n98-magerun config:set web/unsecure/base_url https://staging.domain.tld/
Use the same config:set
command for any other configs that need setting. Note that config:set
can be scoped to a store or view. See the n98-magerun readme. Once you start to automate this process I highly recommend the HarrisStreet-ImpEx module for n98-magerun for managing your environment configs.