Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #/usr/bin/bash
- #
- # dumping and fill prod_dump.sql
- # use : apply_dump.sh or (/usr/bin/apply_dump) <target_db>
- # @author Mikhail <orehov.dev@gmail.com>
- OLD=0
- TARGET_DB=$1
- DUMP="/var/ticketoffices_dump/prod_dump.sql"
- HISTORY=/var/ticketoffices_dump/mysqldump_history
- CURRENT=$(date -u)
- SERVER='69.167.172.120'
- PASS='t;OqHfA]raX9'
- USER='ticketof_mikhail'
- PROD_DB='ticketof_ticketoffices'
- #COLOR
- COLOREND='\033[0m\n' # Text Reset
- RED='\033[0;31m' # Red
- GREEN='\033[0;32m' # Green
- printf $GREEN"TOOLS DUMP PROD DB"$COLOREND
- if [ $# -eq 0 ]
- then
- echo "Usage: apply_dump [TARGET_DB] [OPTION]..."
- echo ""
- echo "options :"
- printf " -old apply_dump [TARGET_DB] -old \t apply old dump\n"
- printf " -new apply_dump [TARGET_DB] -new \t download and apply new dump (default)\n"
- printf "\n\n"
- exit
- fi
- #help check params
- for arg in "$@"
- do
- #if use old dump
- if test $arg = "-old"
- then
- OLD=1
- fi
- #if use new dump
- if test $arg = "-new"
- then
- OLD=0
- fi
- done
- #check Unknown database
- RESULT=`mysqlshow ${TARGET_DB:=undefined} | grep -o ${TARGET_DB:=undefined}`
- if [ "$RESULT" == ${TARGET_DB:=undefined} ]; then
- echo $TARGET_DB" correct"
- else
- printf $RED'use apply_dump [TARGET_DB]'$COLOREND
- mysql -e 'SHOW DATABASES'
- exit;
- fi
- #if need download new dump
- if test $OLD = 0
- then
- printf $GREEN"DOWNLOAD DUMP: $DUMP"$COLOREND
- mysqldump --single-transaction --routines --triggers --skip-tz-utc -h $SERVER -u"$USER" -p"$PASS" $PROD_DB | pv > $DUMP
- FILESIZE=$(du -h "$DUMP")
- echo $CURRENT" download dump size: "$FILESIZE" .upload to:"$TARGET_DB >> $HISTORY
- fi
- printf $GREEN"FILL IN THE DATABASE: $TARGET_DB"$COLOREND
- pv $DUMP | mysql $TARGET_DB
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement