SHARE
TWEET

Untitled

a guest Jul 21st, 2017 441 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/bin/sh
  2.  
  3. DIR=/backup/mysql/
  4. DATESTAMP=$(date +%Y%m%d)
  5. DB_USER=your_backup_user
  6. DB_PASS=your_backup_user_password
  7. MTO="your@email.address"
  8. MSUB="Backup (`echo $USER @ $HOSTNAME`) as on `date`"
  9. MES=/tmp/mybackup.txt
  10.  
  11.  
  12. # remove backups older than $DAYS_KEEP
  13. DAYS_KEEP=30
  14. find ${DIR}* -mtime +$DAYS_KEEP -exec rm -f {} \; 2> /dev/null
  15.  
  16. # create backups securely
  17. umask 006
  18.  
  19. # list MySQL databases and dump each
  20. DB_LIST=`mysql -u $DB_USER -p"$DB_PASS" -e'show databases;'`
  21.  
  22. DB_LIST=${DB_LIST##Database}
  23. for DB in $DB_LIST;
  24. do
  25.   FILENAME=${DIR}${DB}-${DATESTAMP}.sql.gz
  26.   echo "Backup of $FILENAME" > $MES
  27.   mysqldump -u $DB_USER -p"$DB_PASS" --opt --flush-logs $DB | gzip > $FILENAME
  28.   echo "Outputting $FILENAME "
  29.   mutt -s "$MSUB" -a $FILENAME -- $MTO  < $MES
  30. done
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top