Skip to content

Instantly share code, notes, and snippets.

@oterox
Last active December 12, 2015 02:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save oterox/4702468 to your computer and use it in GitHub Desktop.
Save oterox/4702468 to your computer and use it in GitHub Desktop.
bash script to backup WP It generates 3 files: - sql dump - theme folder backup - wp-content folder backup
#!/bin/bash
echo $*
CURRENT_DATE=`date '+%Y%m%d-%Hh%M'`
WP_DATABASE=database_name
WP_FOLDER=wpfolder
WP_THEME=themefoldername
WP_CONTENT_PATH=/var/www/"$WP_FOLDER"/
WP_THEME_PATH=/var/www/"$WP_FOLDER"/wp-content/themes/
#Backup database
mysqldump --add-drop-table -u myuser -pmypass "$WP_DATABASE" > "$CURRENT_DATE"-"$WP_DATABASE".sql
#Backup Theme excluding caches and git files
tar --exclude-caches --exclude ".git/" -czf ${CURRENT_DATE}-${WP_FOLDER}-${WP_THEME}-theme.tar.gz --directory "$WP_THEME_PATH" "$WP_THEME$
#Backup Content excluding caches and git files
tar --exclude-caches --exclude ".git/" -czf ${CURRENT_DATE}-${WP_FOLDER}-content.tar.gz --directory "$WP_CONTENT_PATH" wp-content/
#TO-DO: compress all and upload to ftp server
#TO-DO: option for sending through email
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment