Last active
February 24, 2017 21:52
-
-
Save michaelbrazell/444e826a1813c90802754c6151403745 to your computer and use it in GitHub Desktop.
A simple shell script for backing up your WP Database and WP Files using the wp-cli
This file contains hidden or 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
#!/usr/local/bin/bash | |
# Backup script using wp-cli | |
DBMESSAGE="Backing up database..." | |
FSMESSAGE="Backing up file system..." | |
DONEMESSAGE="Done." | |
MOVEMESSAGE="Moving files to public location..." | |
FINISHED="Backup complete." | |
echo $DBMESSAGE | |
/path/to/wp-cli/wp db export wordpress_$(date +%Y%m%d).sql --path=/var/www/html | |
echo $DONEMESSAGE | |
echo $FSMESSAGE | |
tar --exclude='./wordpress_dev' -zcf wordpress_$(date +%Y%m%d).tar.gz /var/www/html/. | |
echo $DONEMESSAGE | |
echo $MOVEMESSAGE | |
mv ./web_standards_$(date +%Y%m%d).sql /path/to/another/location/ | |
mv ./web_standards_$(date +%Y%m%d).tar.gz /path/to/another/location/ | |
echo $DONEMESSAGE | |
echo $FINISHED |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
wp-cli Backup Script
A simple shell script to backup a local instance of WordPress, database and static files. Ideally this shouldn't be run more than once a day because the file names will have dates at the end. This could be solved by adding a random string or a timestamp, but date is enough for our uses. Feel free to modify or reuse however you like, email me or comment if you have questions or modifications of your own.
Instructions
$ which bash
wp
and you won't need the full path. The permissions on my server were strict so I had to point to the full path.--path=/var/www/html
but your mileage may vary--exclude='./wordpress_dev'
because I have a development instance within my WordPress root. You probably don't have this, so feel free to remove that.mv
commands that move the exported files from where I run them to a public location within my company, so others can grab them if need be. You could be creative and add anscp
here pushing the files up to an Amazon S3 bucket!echo
can be removed if you want to slim it down.