Advertisement
Guest User

Untitled

a guest
Nov 21st, 2016
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.37 KB | None | 0 0
  1. #----------------------------------------------------
  2. #thank to my cat {miao miao} who inspire me pull this code to github
  3. #this script is remember him who passaway in this day 2016-11-17 because get anemia and you always be remember in my deep heart
  4. #credit to miao either nite or morning stay with me when i still coding
  5. #----------------------------------------------------
  6. #!/bin/bash
  7.  
  8. # this script only dump db selected
  9. # Database credentials
  10. # db username
  11. # db password
  12. # db name
  13. # db which need restore
  14. # output directory --> example OUTPUT="/home/desktop/"
  15. # %d-%b-%Y example 18-Nov-2016
  16. # %Y%m%d example 20161118
  17. # file exists
  18. # control to clear function
  19.  
  20. USER="root"
  21. PASSWORD="1234qwer"
  22. DB_NAME="etrade"
  23. BACKUP_db="etrade_bk"
  24. store_loc="${PWD}/honey_pot"
  25. date=$(date +"%Y%m%d")
  26. date_dbss=$(date +"%Y%m%d-%H%M%S")
  27. file=$store_loc/"etrade_today.sql"
  28. $clean_process = false
  29.  
  30. #create a directory for store this db
  31. if [ -d "$store_loc" ] ; then
  32. echo $store_loc "Found"
  33. else
  34. mkdir -p $store_loc
  35. echo $store_loc "Not Found"
  36. fi
  37.  
  38.  
  39. # Delete files older than 30 days
  40. # -f FILE exists and is a regular file
  41. # -e FILE exists
  42. #if [ -f $file ] ; then
  43. # echo $file "Found"
  44. #rm "$OUTPUT/*gz" > /dev/null 2>&1
  45. #else
  46. # echo $file "Not Found"
  47. #fi
  48.  
  49. if [ $clean_process ] ; then
  50. echo "Clear Process is on"
  51. find $store_loc/* -mtime +30 -exec rm {} \;
  52. else
  53. echo "Clear Process is off"
  54. fi
  55.  
  56. databases=`mysql --user=$USER --password=$PASSWORD -e "SHOW DATABASES;" | tr -d "| " | grep -v Database`
  57.  
  58. for db in $databases; do
  59. if [[ "$db" == $DB_NAME ]]; then
  60. echo "Dumping database: $db"
  61. #mysqldump --force --opt --user=$USER --password=$PASSWORD --databases $db > $OUTPUT/$db"_"`date +%Y%m%d-%H%M%S`.sql
  62. mysqldump -u$USER -p$PASSWORD $db > $store_loc/$db"_today".sql
  63. #gzip $OUTPUT/`date +%Y%m%d`.$db.sql
  64. fi
  65. done
  66.  
  67. filename=$(basename "$file")
  68. extension="${filename##*.}"
  69. filename="${filename%.*}"
  70.  
  71. # copy file
  72. if [ -f $file ] ; then
  73. cp $file $store_loc/"etrade_"$date_dbss.sql
  74. fi
  75.  
  76. #restore databases
  77. #if [ -f $file ] ; then
  78. # mysql -u$USER -p$PASSWORD $BACKUP_db < $file
  79. #else
  80. # echo $file "- not found."
  81. #fi
  82.  
  83. #delete databases today
  84. #if [ -f $file ] ; then
  85. # echo $file "will be delete"
  86. #${PWD}/"etrade_today.sql -> this file will be delete
  87. # rm $file
  88. #echo $OUTPUT/*sql
  89. #echo "Any [.sql] file in this directory will be delete"
  90. #rm $OUTPUT/*sql
  91. #fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement