Last active
August 29, 2015 14:14
-
-
Save starkers/1ac725a43849c602987c to your computer and use it in GitHub Desktop.
wp_backup.sh
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
#!/usr/bin/env bash | |
# quickly backs up a wordpress install for you, just specify the wordpress install path | |
ConfFile="$1/wp-config.php" | |
if [ "X$1" == "X" ]; then | |
echo ".. quickly backs up a wordpress database for you, just specify the wordpress install path" | |
echo usage $@ /path/to/wordpress/install/ | |
exit | |
else | |
if [ ! -d "$1" ];then | |
echo "$1 does not exist" | |
exit 1 | |
fi | |
if [ ! -f "$ConfFile" ];then | |
echo "Config file : $ConfFile not found!" | |
exit 1 | |
fi | |
if [ ! -r "$ConfFile" ];then | |
echo "Config file : $ConfFile not readable!" | |
exit 1 | |
fi | |
fi | |
grep -q DB_NAME "$ConfFile" || (echo "DB_NAME not specified in $ConfFile" ; exit 1) | |
NAME="$(grep DB_NAME "$ConfFile" | cut -d "'" -f 4)" | |
grep -q DB_USER "$ConfFile" || (echo "DB_USER not specified in $ConfFile" ; exit 1) | |
USER="$(grep DB_USER "$ConfFile" | cut -d "'" -f 4)" | |
grep -q DB_HOST "$ConfFile" || (echo "DB_HOST not specified in $ConfFile" ; exit 1) | |
HOST="$(grep DB_HOST "$ConfFile" | cut -d "'" -f 4)" | |
grep -q DB_PASSWORD "$ConfFile" || (echo "DB_PASSWORD not specified in $ConfFile" ; exit 1) | |
PASSWORD="$(grep DB_PASSWORD "$ConfFile" | cut -d "'" -f 4)" | |
## where to dump the file | |
String="$(date +%Y%m%d_%H-%M-%S)" | |
File1="$String.sql" | |
File2="$String.tar" | |
#File2="$(date +%Y%m%d_%H-%M-%S.tar)" | |
DumpFile1="$HOME/wp_backup-$HOST-$NAME-$File1" | |
DumpFile2="$HOME/wp_backup-$HOST-$NAME-$File2" | |
echo -n "Proceding with mysqldump: $DumpFile1 " | |
time (mysqldump -u$USER -p$PASSWORD -h$HOST $NAME > $DumpFile1 && echo "success") | |
echo "Creating $DumpFile2.gz" | |
tar cpf "$DumpFile2" "$1" || exit 1 | |
gzip "$DumpFile2" | |
#sleep 10 | |
#du -k "$DumpFile1" | |
#du -k "$DumpFile2.gz" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment