server-tools !?!
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

32 lines
974 B

  1. #!/bin/bash
  2. # Variables
  3. BACKUP_ROOT_MYSQL="/backup/mysql"
  4. MYSQL_BIN=/usr/bin/mysql
  5. MYSQLDUMP_BIN=/usr/bin/mysqldump
  6. MYSQL_USER=backupuser
  7. MYSQL_PASSWORD=backuppwd
  8. GZIP_BIN=/bin/gzip
  9. BACKUP_ROOT_MYSQL_RETENTION=10
  10. # Starting backup
  11. echo "Starting MariaDB backup database process ..."
  12. # Create directories if not exists
  13. mkdir -p ${BACKUP_ROOT_MYSQL}
  14. HOUR=`date +%Y%m%d%H%M`
  15. # Backup with dump the structure
  16. DATABASES=`${MYSQL_BIN} -u${MYSQL_USER} -p${MYSQL_PASSWORD} -e 'SHOW DATABASES' | grep -v - | grep -v Database | grep -v information_schema | grep -v performance_schema | grep -v \|`
  17. for DB in $DATABASES;
  18. do
  19. ${MYSQLDUMP_BIN} -u ${MYSQL_USER} -p${MYSQL_PASSWORD} ${DB} | ${GZIP_BIN} > ${BACKUP_ROOT_MYSQL}/${DB}_${HOUR}.sql.gz
  20. if [ $? -ne 0 ]; then
  21. echo "ERROR - Dump for ${DB}"
  22. fi
  23. done
  24. # Purge old backup
  25. echo "Starting MariaDB purge database process ..."
  26. find ${BACKUP_ROOT_MYSQL} -type f -mtime +${BACKUP_ROOT_MYSQL_RETENTION} -exec rm -f {} \;