extended.sh 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #!/bin/bash
  2. ##################################
  3. #
  4. # Installation
  5. #
  6. # 0. Place this script in /usr/local/sbin with 700 rights
  7. # 1. Create a user in MySQL with SELECT, RELOAD and LOCK TABLES on all databases.
  8. # 2. fill in the username and password of the mysql account below
  9. # 3. create the directory /var/myexport
  10. # 4. crontab this script to run 3 times a day
  11. #
  12. #################################
  13. USER=<user>
  14. #PASS=<pass>
  15. COPIES=2
  16. BASE=<path>
  17. if [ ! -d $BASE ]
  18. then
  19. echo "Backup share not available, stopping"
  20. exit 1
  21. fi
  22. if [ $# -gt 0 ]; then
  23. DBLIST="$*"
  24. else
  25. #DBLIST=`mysql -u $USER --password=$PASS -s -e 'show databases'`
  26. DBLIST=`mysql -u $USER -s -e 'show databases'`
  27. fi
  28. for N in $DBLIST;
  29. do
  30. case $N in
  31. "Database")
  32. echo "ignoring Database"
  33. ;;
  34. "information_schema")
  35. echo "ignoring Information_Schema"
  36. ;;
  37. "performance_schema")
  38. echo "ignoring Performance_schema"
  39. ;;
  40. *)
  41. echo "dumping $N"
  42. i=$(($COPIES - 1))
  43. while [ $i -ge 0 ];
  44. do
  45. [ -s $BASE/$N.sql.$i.gz ] && mv $BASE/$N.sql.$i.gz $BASE/$N.sql.$(($i+1)).gz
  46. i=$(($i-1))
  47. done
  48. #mysqldump -u $USER --opt --password=$PASS $N | gzip >$BASE/$N.sql.0.gz
  49. mysqldump -u $USER --opt $N | gzip >$BASE/$N.sql.0.gz
  50. ;;
  51. esac
  52. done