Last active
July 20, 2017 08:02
-
-
Save hmngwy/8101c90be1a5326f1e59ec8a50c4245e to your computer and use it in GitHub Desktop.
Backs Up Wordpress Folder and DB in one go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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