0

I have the below configuration for rotating the DB backups. The /var/mysql_backup/data/ contains two subdirectories db1 and db2.

/var/mysql_backup/data/*/db.sql.gz {
    daily
    rotate 7
    nocompress
    notifempty
    missingok
    create 640 root root
    dateext
    dateformat _%Y_%m_%d_%s
    extension .sql.gz
    
    postrotate

        PATH=/var/mysql_backup/data/
        MYSQL_USER=USER
        MYSQL_PASS='PASS'
        MYSQL_CONN="-u${MYSQL_USER} -p${MYSQL_PASS}"
        MYSQLDUMP_OPTIONS=" --single-transaction --quick"

        #Backup for db1
        mysqldump ${MYSQL_CONN} ${MYSQLDUMP_OPTIONS} db1  > ${PATH}/db1/db.sql
        gzip -9f ${PATH}/db1/db.sql

        #Backup for db2
        mysqldump ${MYSQL_CONN} ${MYSQLDUMP_OPTIONS} db2  > ${PATH}/db1/db.sql
        gzip -9f ${PATH}/db2/db.sql
    endscript
}

My question is: the mysqldump and gzip for each DB running once or twice? If they are running twice, then how to make them run once?

Note: I know that I can define configurations for db1 and db2 separately. But I'm looking for a cleaner solution.

Niyaz
  • 113
  • 5

0 Answers0