Quick WP BackUp Script

  January 2, 2018

I’ve been doing a lot of wordpress development on *nix based machines over the last couple weeks and I’ve been needing to quickly archive and backup my work everyday. I wrote this little bash script that quickly does the backup of the wp-content directory and uses the WPCLI command to export the database.

I’ve named the file as bkup.sh and placed it in the WordPress root directory where I can easily run it on demand sh bkup.sh . After the script runs the archive should be located in the WordPress root directory as site_wpcontent_bkup_12_30_2017.zip file. Obviously there’s more options one could add such as to moving the archive to a cloud backup storage or set it up as a cron job but for now it works well me – it’s a quick and dirty but it works with no plugins!


#get the current date
NOW=$(date +"%m_%d_%Y")

#set archive backup name and append the date

#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 . . .

  Tech   wordpress