Skip to content

Instantly share code, notes, and snippets.

Last active March 20, 2023 18:07
What would you like to do?
Storing WordPress files and database with WP-CLI on the server.

WordPress Backups with WP-CLI

/usr/local/bin/wp db --path=/var/www/websites/wp - | gzip > /var/www/backups/db_backup-$(date +%Y-%m-%d-%H%M%S).sql.gz &
tar --create --gzip --absolute-names --file=/var/www/backups/wp_backup-$(date +%Y-%m-%d-%H%M%S).tar.gz --exclude=*.tar.gz /var/www/websites/wp
30 18 * * * sh /var/www/backups/ > /var/www/logs/cronlog 2>&1
wp db export - | gzip > ./db_backup-$(date +%Y-%m-%d-%H%M%S).sql.gz
tar --create --gzip --verbose --absolute-names --file=./wp_backup-$(date +%Y-%m-%d-%H%M%S).tar.gz --exclude=*.tar.gz /var/www/websites/wp
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment