Skip to content

Instantly share code, notes, and snippets.

@mkeneqa
Last active November 8, 2019 09:26
Show Gist options
  • Select an option

  • Save mkeneqa/eb8c3a6ff01e839527941eb4e1ee6ba0 to your computer and use it in GitHub Desktop.

Select an option

Save mkeneqa/eb8c3a6ff01e839527941eb4e1ee6ba0 to your computer and use it in GitHub Desktop.
Bash script to backup WordPress

WP Bash Backup Script

This bash script quickly does the backup of the wp-content directory and uses the WPCLI command to export the database.

Place the script in the WordPress root directory and run sh bkup.sh .

After the script executes an archive should be located in the WordPress root directory similar to this: site_wpcontent_bkup_12_30_2019.zip.

#!/bin/bash
#get the current date
NOW=$(date +"%m_%d_%Y")
#set archive backup name and append the date
SITEBKUPNAME="site_wpcontent_bkup_$NOW.zip"
#export database
wp db export
#zip up the wp-content dir
zip -r $SITEBKUPNAME wp-content/
#add the exported file to the zip archive
zip -g $SITEBKUPNAME *.sql
#remove the sql file after it is added to archiive
rm *.sql
# ??could copy file to third party cloud storage .
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment