Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- #
- # MySQL Backup Script
- # Dumps mysql databases to a file for another backup tool to pick up.
- #
- # MySQL code:
- # GRANT SELECT, RELOAD, LOCK TABLES ON *.* TO 'user'@'localhost'
- # IDENTIFIED BY 'password';
- # FLUSH PRIVILEGES;
- #
- ##### START CONFIG ###################################################
- USER=backup
- DIR=/var/lib/mysql/backup
- ROTATE=6
- # Use a pwd file. See https://dev.mysql.com/doc/refman/5.1/en/password-security-user.html
- PWD_FILE=$(mktemp ${DIR}/backup.cnf.XXXX)
- echo "
- [client]
- password=sirugrwiuwiuwguisrkogos
- " >> $PWD_FILE
- PREFIX=mysql_backup_
- ADDITIONAL_OPTIONS="--ignore-table=mysql.event"
- ##### STOP CONFIG ####################################################
- PATH=/usr/bin:/usr/sbin:/bin:/sbin
- set -o pipefail
- cleanup()
- {
- find "${DIR}/" -maxdepth 1 -type f -name "${PREFIX}*.sql*" -mtime +${ROTATE} -print0 | xargs -0 -r rm -f
- }
- mysqldump --defaults-file=${PWD_FILE} -u${USER} --opt --flush-logs --single-transaction
- ${ADDITIONAL_OPTIONS}
- --all-databases | bzcat -zc > ${DIR}/${PREFIX}`date +%Y%m%d-%H%M%S`.sql.bz2
- if [ $? -eq 0 ] ; then
- cleanup
- fi
- rm -rf $PWD_FILE
- # time /usr/local/sbin/mysqlbackup.sh
- real 21m35.647s
- user 20m47.059s
- sys 0m7.843s
- # du -sh mysql_backup_20160223-123920.sql
- 4.9G mysql_backup_20160223-123920.sql
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement