Skip to content

Instantly share code, notes, and snippets.

@wathmal
Last active January 19, 2017 09:58
Show Gist options
  • Save wathmal/7a958daf90975a80425fd9f30d468096 to your computer and use it in GitHub Desktop.
Save wathmal/7a958daf90975a80425fd9f30d468096 to your computer and use it in GitHub Desktop.
bash script to backup wordpress site and database to dropbox
#!/usr/bin/env bash
BLOG_DIR="/var/www/html/blog/"
OUT_DIR="/home/pi/temp/"
PREFIX="wp_"
TS=$(date +"%Y-%m-%d");
# zip the whole blog directory
echo "compressing $BLOG_DIR directory"
zip -q -r "$OUT_DIR$PREFIX$TS.zip" "$BLOG_DIR"
# dump the wordpress db
echo "dumping wordpress db"
/usr/local/bin/wp db export "$OUT_DIR$PREFIX$TS.sql" "--path=$BLOG_DIR"
# uploading to dropbox
echo "uploading to dropbox"
/home/pi/bin/dropbox_uploader -p upload "$OUT_DIR$PREFIX$TS.sql" /
/home/pi/bin/dropbox_uploader -p upload "$OUT_DIR$PREFIX$TS.zip" /
# delete backups
echo "deleting backups"
rm $OUT_DIR$PREFIX$TS.sql
rm $OUT_DIR$PREFIX$TS.zip
echo "all done!"
echo "$TS"
@wathmal
Copy link
Author

wathmal commented Jan 19, 2017

backup wordpress site and database to dropbox

a bash script to backup wordpress website and its database to dropbox. run this script as a cron job to maintain backups at pre-defined time intervals.

dependencies

wp-cli need to be installed.
http://wp-cli.org/

dropbox_uploader need be installed and setup to use your dropbox app. make sure to create a symlink of dropbox_uploader to /home/pi/bin/.
https://github.com/andreafabrizi/Dropbox-Uploader

change the locations for binaries. /home/pi/ to home/username/

enjoy. ❤️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment