Last active
August 29, 2015 14:15
-
-
Save jperocho/536d485f825ffc1a2cc8 to your computer and use it in GitHub Desktop.
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
#!/bin/bash | |
# By John Mark Perocho | |
# PixelTracer 2015 | |
# This is a script use to backup wordpress app in webfaction | |
# Usage: backup [FOLDER LOCATION] -optional [NAME OF TAR FILE] | |
path=${1%%+(/)} | |
tarname=$2 | |
pathname=$(echo $1 | sed -r 's/[\.\/]//g') | |
tarit () { | |
echo "Site Backing up ..." | |
if [ -f $path/wp-config.php ]; then | |
dbname=`grep DB_NAME $path/wp-config.php | cut -d \' -f 4` | |
dbuser=`grep DB_USER $path/wp-config.php | cut -d \' -f 4` | |
dbpass=`grep DB_PASSWORD $path/wp-config.php | cut -d \' -f 4` | |
echo "Folder is Wordpress. Backing up database ..." | |
mysqldump -u$dbuser -p$dbpass $dbname -r $path/db.sql | |
tar zcf $1.tar.gz $path | |
rm $path/db.sql | |
else | |
echo "Folder is not Wordpress" | |
tar zcf $1.tar.gz $path | |
fi | |
} | |
checktar () { | |
echo Backing up ${path%%+(/)} to $1.tar.gz | |
if [ -f $1.tar.gz ]; then | |
read -p "$1.tar.gz already exist. Do you want to overwrite? [Y/N]" yn | |
case $yn in | |
[Yy]* ) tarit $1 | |
exit;; | |
[Nn]* ) exit;; | |
* ) exit;; | |
esac | |
else | |
tarit $1 | |
fi | |
} | |
if [[ $# -eq 0 ]]; then | |
echo 'Usage: backup [FOLDER LOCATION] -optional [NAME OF TAR FILE]' | |
echo 'Example: bash backup /var/www www' | |
exit 1 | |
else | |
if [[ ! -d $path ]]; then | |
echo "ERROR: Can't find directory..." | |
else | |
if [[ -z "$tarname" ]]; then | |
checktar $pathname | |
else | |
checktar $tarname | |
fi | |
fi | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment