I wanted a script to automate the copying of a live website to a "staging" site on the same machine. This was tested on Debian Jessie.
Before you begin:
In this case make sure the same database user has the appropriate permissions on both databases. And also note that the RELOAD privilege is needed to use the `mysqldump --lock-all-tables` option on the existing live database.
Script below: