Skip to content

Instantly share code, notes, and snippets.

@hmngwy
Last active July 20, 2017 08:02
Show Gist options
  • Save hmngwy/8101c90be1a5326f1e59ec8a50c4245e to your computer and use it in GitHub Desktop.
Save hmngwy/8101c90be1a5326f1e59ec8a50c4245e to your computer and use it in GitHub Desktop.
Backs Up Wordpress Folder and DB in one go
function wpbackup {
folder=$1
name=$1
dest="."
if [ ! -z $2 ]; then
dest=$2
fi
if [ ! -z $3 ]; then
name=$3
fi
timestamp=$(date +'%Y-%m-%d')
WPDBNAME=`cat $folder/wp-config.php | grep DB_NAME | cut -d \' -f 4`
WPDBUSER=`cat $folder/wp-config.php | grep DB_USER | cut -d \' -f 4`
WPDBPASS=`cat $folder/wp-config.php | grep DB_PASSWORD | cut -d \' -f 4`
mysqldump -u "$WPDBUSER" -p"$WPDBPASS" "$WPDBNAME" > "$dest/$name-$WPDBNAME-$timestamp.sql"
tar -zcvf "$dest/$name-$timestamp.tgz" "$folder" "$dest/$name-$WPDBNAME-$timestamp.sql"
}
wpbackup wp_root
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment