Skip to content

Instantly share code, notes, and snippets.

@hofmannsven
Last active October 6, 2023 21:05
  • Star 37 You must be signed in to star a gist
  • Fork 17 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save hofmannsven/f68ba69b5d540c6d5c83 to your computer and use it in GitHub Desktop.
Storing WordPress files and database with WP-CLI on the server.

WordPress Backups with WP-CLI

#!/bin/sh
/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/backup.sh > /var/www/logs/cronlog 2>&1
#!/bin/sh
wp db export - | gzip > ./db_backup-$(date +%Y-%m-%d-%H%M%S).sql.gz
#!/bin/sh
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