Advertisement
Guest User

Untitled

a guest
Mar 11th, 2017
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.70 KB | None | 0 0
  1. #/usr/bin/bash
  2. #
  3. # dumping and fill prod_dump.sql
  4. # use : apply_dump.sh or (/usr/bin/apply_dump) <target_db>
  5. # @author Mikhail <orehov.dev@gmail.com>
  6.  
  7. OLD=0
  8. TARGET_DB=$1
  9. DUMP="/var/ticketoffices_dump/prod_dump.sql"
  10. HISTORY=/var/ticketoffices_dump/mysqldump_history
  11. CURRENT=$(date -u)
  12. SERVER='69.167.172.120'
  13. PASS='t;OqHfA]raX9'
  14. USER='ticketof_mikhail'
  15. PROD_DB='ticketof_ticketoffices'
  16. #COLOR
  17. COLOREND='\033[0m\n'      # Text Reset
  18. RED='\033[0;31m'          # Red
  19. GREEN='\033[0;32m'        # Green
  20.  
  21. printf $GREEN"TOOLS DUMP PROD DB"$COLOREND
  22.  
  23. if [ $# -eq 0 ]
  24. then
  25.     echo "Usage: apply_dump [TARGET_DB] [OPTION]..."
  26.     echo ""
  27.     echo "options :"
  28.     printf "  -old apply_dump [TARGET_DB] -old \t apply old dump\n"
  29.     printf "  -new apply_dump [TARGET_DB] -new \t download and apply new dump (default)\n"
  30.     printf "\n\n"
  31.     exit
  32. fi
  33.  
  34. #help check params
  35. for arg in "$@"
  36. do 
  37.     #if use old dump
  38.     if test $arg = "-old"
  39.     then
  40.         OLD=1
  41.     fi
  42.     #if use new dump
  43.     if test $arg = "-new"
  44.     then
  45.         OLD=0
  46.     fi
  47. done
  48.  
  49. #check Unknown database
  50. RESULT=`mysqlshow ${TARGET_DB:=undefined} | grep -o ${TARGET_DB:=undefined}`
  51. if [ "$RESULT" == ${TARGET_DB:=undefined} ]; then
  52.     echo $TARGET_DB" correct"
  53. else
  54.     printf $RED'use apply_dump [TARGET_DB]'$COLOREND
  55.     mysql -e 'SHOW DATABASES'
  56.     exit;
  57. fi
  58.  
  59. #if need download new dump
  60. if test $OLD = 0
  61. then
  62.     printf $GREEN"DOWNLOAD DUMP: $DUMP"$COLOREND
  63.     mysqldump --single-transaction --routines --triggers --skip-tz-utc -h $SERVER -u"$USER" -p"$PASS" $PROD_DB | pv > $DUMP
  64.     FILESIZE=$(du -h "$DUMP")
  65.     echo $CURRENT" download dump size: "$FILESIZE" .upload to:"$TARGET_DB >> $HISTORY
  66. fi
  67.  
  68. printf $GREEN"FILL IN THE DATABASE: $TARGET_DB"$COLOREND
  69. pv $DUMP | mysql $TARGET_DB
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement