Score:0

How many times will postrotate run when defining logrotate for multiple directories?

us flag

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.

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.