Skip to content

Built a staging workflow with rsync and wp-cli, here's my script

Web Hosting by mediaaustin 2 replies 122 views
9 #1

Been running this for a few client sites on Hostinger's shared plan. Nothing fancy, but it beats FTP.

#!/bin/bash
# push-staging.sh
REMOTE="[email protected]:/public_html"
rsync -avz --exclude='wp-config.php' ./ $REMOTE
ssh [email protected] "cd /public_html && wp search-replace 'example.com' 'staging.example.com.com' --allow-root"

Hot take: most staging "solutions" are just rsync with marketing. This handles the DB URL swap so clients stop emailing me about broken media links.

For what it's worth, I skip wp-config.php because Hostinger stores staging DB creds differently and I got burned once overwriting it.

What would you add?

SPF, DKIM, DMARC — holy trinity ✉️
#2

1) safety checks missing
A) dry-run mode
I) rsync -n first
Ii) wp search-replace --dry-run
B) backup before push
I) wp db export pre-staging-$(date +%F).sql
2) rollback path
A) timestamped releases
B) symlink swap
3) your script lacks
A) exit code checks
B) logging

#3

¡the script is good but the danger is big!

I use vos in the server red of Vultr, and one time the replace went wrong in all tables jajaja. Now I put the flag --all-tables-with-prefix and the skip-columns for the serialized data. The wp-cli has the flag --precise for this, very important!

Also the url of production must be with https and the staging with http, the replace double is needed. ¡I learned of the way hard!

hot air, steady hand, magic smoke

Post a reply

You need an account to reply. Log in or register to join the conversation.

Post reply Preview Save draft