Created
December 8, 2015 23:27
-
-
Save Nilpo/251de565b0fd197d5b95 to your computer and use it in GitHub Desktop.
A Wordpress Backup Shell Script
This file contains hidden or 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
#!/bin/bash | |
# usage: ./wpbackup.sh domain.com | |
DOMAIN="$1"; # domain name to backup | |
BACKUP="$HOME/backups"; # store backups here | |
HOSTPATH="$HOME"; # path where hosted domains are | |
backmeup () { | |
local _N _U _P _H FS FT TD WP; | |
FT=`date +$BACKUP/$DOMAIN-%m-%d-%g-%H%M.tar.gz`; | |
FS=`date +$BACKUP/$DOMAIN-%m-%d-%g-%H%M.sql`; | |
TD=$HOSTPATH/$DOMAIN; | |
WP=$TD/wp-config.php; | |
( cd $TD || { | |
echo "bad $TD" && return 2 | |
}; | |
eval $(sed -n "s/^d[^D]*DB_\([NUPH]\)[ASO].*',[^']*'\([^']*\)'.*/_\1='\2'/p" $WP); | |
mysqldump -u$_U -p$_P -h$_H $_N > $FS; | |
tar -czPf $FT $TD ) | |
} | |
if [ "$#" -ne 1 ]; then | |
echo "usage: $0 domain.com" | |
exit 0 | |
fi | |
if [ -d "$HOSTPATH/$DOMAIN/" ]; then | |
backmeup | |
exit 0 | |
else | |
echo "directory not found" | |
exit 0 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment