Instantly share code, notes, and snippets.

What would you like to do?
Backing up small wp site with DB

Backup for small WP sites using dropbox and wp-cli and 🎩

Go to :

Create new app call it anything it's gonna be your private app.

Generated access token and save it somewhere in your locker 😄

Download file and change directories path and DROPBOX_TOKEN

sudo chmod +x

Setup crontab with crontab -e add following line there

0 5 * * * /root/ > /dev/null 2>&1

This will backup site everyday at 5 am.


  • This scripts assumes your installation will be under if not it's time to fork this and modify script.
  • This will backup your WP tables and wp-content folder.
  • You can also change path of
  • You should clean up your dropbox folder before you run out of memory.
  • Modify crontab if you want to change backup interval to less frequent or more frequent.


# Generate your Dropbox token:
DROPBOX_TOKEN={dropbox access token here}
# Directory that holds your WordPress sites' root folders
# If you have multiple folders with WordPress sites, add/remove them from this array
directories=( "" "" )
for dir in "${directories[@]}"
printf "Backing up $PREFIX/$dir \n"
cd $PREFIX/$dir/htdocs
printf "Exporting database... \n"
wp db export --add-drop-table $DATABASE_FILENAME --allow-root
cd ..
printf "Compressing directory... \n"
BACKUP_FILENAME=$dir.$(date -d today "+%Y%m%d").tar.gz
tar czf $BACKUP_FILENAME htdocs/$DATABASE_FILENAME htdocs/wp-content/
printf "Uploading to Dropbox... \n"
curl -k --progress-bar -i --globoff -o /tmp/dropbox --upload-file $BACKUP_FILENAME$BACKUP_FILENAME -H "Authorization:Bearer $DROPBOX_TOKEN"
printf "Removing files... \n"
printf "Done!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment