Last active
November 7, 2016 17:29
-
-
Save 1d10t/56a842f36756c38008d3585cd19dfd94 to your computer and use it in GitHub Desktop.
masterhost.ru bitrix 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="www" | |
AWK_EXPR='{if($0~/\.(php|js|css|tpl|sql|xml|htaccess|ini)/&&$0!~/\/(tpl_c|upload|managed_cache|stack_cache|cache\/(cs|j)s\/s[0-9]+|app\/bitrix\/cache|bitrix\/modules\/[^\/]+\/install\/)\//)print $0}' | |
DOMAIN=`basename \`pwd\`` | |
LIST="Include" | |
ARCHIVE=$WWW"/"$DOMAIN"-"`date '+%F'`".tgz" | |
if [ -n "$1" ] | |
then | |
AWK_EXPR='{if($0!~/\/(tpl_c)\//)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