The paths used may be server specific. Adjust accordinarly. Simple commands and bash scripts useful for quick backups of Wordpress.
-
-
Save inspiredearth/783b0cb68b10a20872a1f7017d9a9dea to your computer and use it in GitHub Desktop.
Storing WordPress files and database with WP-CLI on the server.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
tar -czf ~/wp-backups/plugins-$(date +%Y-%m-%d-%H%M%S).tar.gz ~/httpdocs/wp-content/plugins | |
echo "Plugins backed up. Now doing themes." | |
tar -czf ~/wp-backups/themes-$(date +%Y-%m-%d-%H%M%S).tar.gz ~/httpdocs/wp-content/themes | |
echo "Themes backed up. Now doing database." | |
wp db export - | gzip > ~/wp-backups/db_backup-$(date +%Y-%m-%d-%H%M%S).sql.gz | |
echo "Database backed up" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 18 * * * sh /var/www/backups/backup.sh > /var/www/logs/cronlog 2>&1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
wp db export - | gzip > ./db_backup-$(date +%Y-%m-%d-%H%M%S).sql.gz |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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