Guest User

Untitled

a guest
Apr 19th, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.18 KB | None | 0 0
  1. #!/bin/sh
  2. #==========================================================================
  3. # RETRIX HOSTING - INTERNAL USE ONLY
  4. #==========================================================================
  5. #
  6.  
  7. if [ -z $1 ]; then
  8. cat << __EOT
  9.  
  10. Usage: $DB_NAME <backup path> <database name> <db user> <db password>
  11.  
  12. If your backup path has a file called <database name>.tables, the script will only backup the tables specified. There should be one line in the file with all of the tables listed with spaces inbetween.
  13.  
  14. __EOT
  15. exit
  16. fi
  17.  
  18. if [ -x /usr/local/mysql/bin/mysqldump ]; then
  19. MYSQLDUMP_CMD="/usr/local/mysql/bin/mysqldump"
  20. else
  21. MYSQLDUMP_CMD="/usr/local/bin/mysqldump"
  22. fi
  23. DATE=`date +%Y.%m.%d-%H.%M`
  24. TARGET=$1
  25. DB_NAME=$2
  26. DB_USER=$3
  27. if [ ! -z $4 ]; then
  28. DB_PASS="-p$4"
  29. fi
  30.  
  31. mkdir /tmp/$DB_NAME-$DATE
  32. if [ ! -d /tmp/$DB_NAME-$DATE ]; then
  33. echo "Could not make temp dir. Aborting..."
  34. exit
  35. fi
  36. cd /tmp/$DB_NAME-$DATE
  37.  
  38. if [ -e $TARGET/$DB_NAME.tables ]; then
  39. TABLES=`/usr/bin/head -n 1 $TARGET/$DB_NAME.tables`
  40. else
  41. TABLES=""
  42. fi
  43.  
  44. $MYSQLDUMP_CMD -u $DB_USER $DB_PASS $DB_NAME $TABLES >$DB_NAME-$DATE.txt
  45.  
  46. gzip $DB_NAME-$DATE.txt
  47.  
  48. mv $DB_NAME-$DATE.txt.gz $TARGET 2>/dev/null
  49.  
  50. cd /tmp
  51. rm -rf /tmp/$DB_NAME-$DATE
Add Comment
Please, Sign In to add comment