Last active
January 5, 2018 10:42
-
-
Save petermolnar/f22a8c80dbc412b8c0f0936346b52ff2 to your computer and use it in GitHub Desktop.
cron file for wordpress backup and wp-cron using wp-cli
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
MAILTO="you@domain.com" | |
SHELL=/bin/bash | |
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin | |
# prerequisities: | |
# sudo wget -q -O/usr/local/bin/wpcli https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar; sudo chmod 0755 /usr/local/bin/wpcli | |
# WP CRON | |
* * * * * wpuser cd /path/to/wordpress; wpcli cron event run --due-now --quiet | |
# WP CLI EXPORT | |
30 11 * * * wpuser cd /path/to/wordpress; wpcli export --quiet --max_file_size=500 --dir=/path/to/backups; cd /path/to/backups; for xml in $(ls *.xml); do xz -z6 ${xml}; done | |
# WP DB backup | |
1 11 * * * wpuser CONF="/path/to/wordpress/wp-config.php"; if [ ! -f "$CONF" ]; then echo "no WP config!"; exit 1; fi; USER=`grep DB_USER ${CONF} | cut -d"'" -f4`; PASS=`grep DB_PASSWORD ${CONF} | cut -d"'" -f4`; DB=`grep DB_NAME ${CONF} | cut -d"'" -f4`; /usr/bin/mysqldump -S /var/run/mysqld/mysqld.sock -u${USER} -p${PASS} ${DB} | xz -z6 >/path/to/backups/wp-mysql-`date +"\%Y-\%m-\%d"`.sql.xz | |
# WP update | |
1 16 * * * wpuser cd /path/to/wordpress; wpcli core update --quiet; wpcli plugin update --all --quiet; wpcli theme update --all --quiet; | |
# Cleanup old exports | |
1 21 * * * wpuser cd /path/to/backups; find . -mtime +30 -exec rm {} \; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment