SHARE
TWEET

MySQL Snapshots

a guest Nov 15th, 2012 238 Never
  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
RAW Paste Data
Top