Skip to content

Instantly share code, notes, and snippets.

@SpartakusMd
Last active December 24, 2016 06:26
Show Gist options
  • Save SpartakusMd/ef573ea651f9ec46be55 to your computer and use it in GitHub Desktop.
Save SpartakusMd/ef573ea651f9ec46be55 to your computer and use it in GitHub Desktop.
Wordpress Backup
#!/bin/bash
# Usage
# backup.sh path-to-wordpress-folder
WPDIR=${1:-www}
echo "Making files backup"
CurrentDir=${PWD##*/}
FILENAME="$CurrentDir ($(date '+%F'))"
tar -czf "$FILENAME.tgz" --exclude="$WPDIR/wp-content/uploads" --exclude-vcs $WPDIR
echo "Making database backup"
WPDBHOST=`cat $WPDIR/wp-config.php | grep DB_HOST | cut -d \' -f 4`
WPDBNAME=`cat $WPDIR/wp-config.php | grep DB_NAME | cut -d \' -f 4`
WPDBUSER=`cat $WPDIR/wp-config.php | grep DB_USER | cut -d \' -f 4`
WPDBPASS=`cat $WPDIR/wp-config.php | grep DB_PASSWORD | cut -d \' -f 4`
mysqldump -h $WPDBHOST -u $WPDBUSER -p$WPDBPASS $WPDBNAME > "$FILENAME.sql" && tar -zcf "$FILENAME.sql.tgz" "$FILENAME.sql" && rm "$FILENAME.sql"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment