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.
|
- #!/bin/bash
-
- # Variables
- BACKUP_ROOT_MYSQL="/backup/mysql"
- MYSQL_BIN=/usr/bin/mysql
- MYSQLDUMP_BIN=/usr/bin/mysqldump
- MYSQL_USER=backupuser
- MYSQL_PASSWORD=backuppwd
- GZIP_BIN=/bin/gzip
- BACKUP_ROOT_MYSQL_RETENTION=10
-
- # Starting backup
- echo "Starting MariaDB backup database process ..."
-
- # Create directories if not exists
- mkdir -p ${BACKUP_ROOT_MYSQL}
- HOUR=`date +%Y%m%d%H%M`
-
- # Backup with dump the structure
- 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 \|`
- for DB in $DATABASES;
- do
- ${MYSQLDUMP_BIN} -u ${MYSQL_USER} -p${MYSQL_PASSWORD} ${DB} | ${GZIP_BIN} > ${BACKUP_ROOT_MYSQL}/${DB}_${HOUR}.sql.gz
- if [ $? -ne 0 ]; then
- echo "ERROR - Dump for ${DB}"
- fi
- done
-
- # Purge old backup
- echo "Starting MariaDB purge database process ..."
- find ${BACKUP_ROOT_MYSQL} -type f -mtime +${BACKUP_ROOT_MYSQL_RETENTION} -exec rm -f {} \;
|