Create full site Zip Backup

The following command will create a full backup in a tar file.
The main reason I’m adding it here is because I want a exhaustive and growing list of excludes.

Run this above the public_html. This way the backup won’t be publicly available.

wp db dump dump.sql --path=./public_html
tar --exclude={'wp-content/aiowps_backups','wp-content/backup','wp-content/cache','wp-content/updraft'} -vczf public_html.tar.gz public_html/ dump.sql
rm dump.sql

Importing the Dump.

The unzip command:

tar -xf ./public_html.tar.gz
echo 'path: ./public_html' > wp-cli.yml

Now change the DB settings in the wp-config.

wp db reset --yes
wp db import dump.sql

Change the url.

wp search-replace --all-tables --report-changed-only // //

After testing the site works you can delete the import files.

rm ./public_html.tar.gz ./dump.sql

Staging site.

If this copy works as a staging site and should not be live (yet) I recommend using Restricted Site Access.
By default it will redirect everybody to the login screen. Under Settings > reading you can tweak a lot.

wp plugin install --activate restricted-site-access