Last active
November 7, 2016 17:28
-
-
Save 1d10t/939548054bca5d916983cf0207dbd83d to your computer and use it in GitHub Desktop.
beget.ru cs-cart archive script
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/sh | |
WWW="public_html" | |
AWK_EXPR='{if($0~/\.(php|js|css|tpl|sql|xml|htaccess)/&&$0!~/\/(var\/(cache|backups|files))\//)print $0}' | |
DOMAIN=`basename \`pwd\`` | |
LIST="Include" | |
ARCHIVE=$WWW"/"$DOMAIN"-"`date '+%F'`".tgz" | |
if [ -n "$1" ] | |
then | |
AWK_EXPR='{if($0!~/\/(var\/(cache|backups))\//)print $0}' | |
ARCHIVE=$WWW"/"$DOMAIN"-"`date '+%F'`"-full.tgz" | |
LIST="Include-full" | |
fi | |
URL="http://"$DOMAIN"/"`basename $ARCHIVE` | |
MYSQL_CNF="../mysql_"$DOMAIN".cnf" | |
MYSQL_DB_FILE="../mysql_"$DOMAIN".db" | |
MYSQL_DUMP=$WWW"/dump.sql" | |
if [ -f $MYSQL_DB_FILE ] | |
then | |
MYSQL_DB=`cat $MYSQL_DB_FILE` | |
MYSQL_CNF_ARG="" | |
if [ -f $MYSQL_CNF ] | |
then | |
MYSQL_CNF_ARG="--defaults-extra-file="$MYSQL_CNF | |
fi | |
mysqldump $MYSQL_CNF_ARG $MYSQL_DB > $MYSQL_DUMP | |
fi | |
find -L $WWW -type f -print | awk "$AWK_EXPR" > $LIST | |
if [ -n "$2" ] | |
then | |
tar czvf - -T $LIST | ssh $2 "cat - > "`basename $ARCHIVE` | |
if [ -f $MYSQL_DUMP ] | |
then | |
echo "Press <ENTER> to delete file(s)" | |
echo -e "\t"$MYSQL_DUMP | |
read crlf | |
rm -f $MYSQL_DUMP | |
fi | |
else | |
tar czvf $ARCHIVE -T $LIST | |
echo "Download file:" | |
echo -e "\t"$URL | |
echo "Press <ENTER> to delete file(s)" | |
echo -e "\t"$ARCHIVE | |
if [ -f $MYSQL_DUMP ] | |
then | |
echo -e "\t"$MYSQL_DUMP | |
read crlf | |
rm -f $ARCHIVE $MYSQL_DUMP | |
else | |
read crlf | |
rm -f $ARCHIVE | |
fi | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment