Pastebin launched a little side project called HostCabi.net, check it out ;-)Don't like ads? PRO users don't see any ads ;-)
Guest

MySQL Snapshots

By: a guest on Nov 15th, 2012  |  syntax: Bash  |  size: 0.82 KB  |  hits: 158  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. #!/bin/sh
  2.  
  3. DIR=/opt/sql
  4. USERNAME="userThatCanRead"
  5. PASSWORD="Password"
  6.  
  7. rm $DIR/*.gz 2>&1 > /dev/null
  8.  
  9. DATABASES=$(echo "SHOW DATABASES" | mysql -u $USERNAME --pass=$PASSWORD | grep -v Database)
  10.  
  11. for DB in $DATABASES
  12. do
  13.         if ( [ "${DB}" != "information_schema" ] && [ ${DB} != "performance_schema" ] )
  14.         then
  15.                 mysqldump -u $USERNAME --password=$PASSWORD -c --databases ${DB} > $DIR/${DB}.sql
  16.                 gzip $DIR/${DB}.sql
  17.         fi
  18. done
  19.  
  20. DAY=`date +%u`
  21. if [ $DAY -eq '7' ]
  22. then
  23.         DX=`date +%Y%m%d`
  24.         for DB in $DATABASES
  25.         do
  26.                 if ( [ "${DB}" != "information_schema" ] && [ ${DB} != "performance_schema" ] )
  27.                 then
  28.                         cp $DIR/${DB}.sql.gz $DIR/historical/${DB}-$DX.sql.gz
  29.                 fi
  30.         done
  31. fi