0

Trying to configure logrotate for 10 daily rotation in my dump folder I have 11 rotations (mydump.sql, mydump.sql.1 ... mydump.sql.11), why?

This is my logrotate configuration file in /etc/logrotate.d/ (I'm running Ubuntu server 12.4 LTS with logrotate 3.7.8):

/home/alepac/dumps/mydump.sql {
    rotate 10
    daily
    nomissingok
    create
    nocompress
    nocopy
    prerotate
        mysqldump -u alepac -pThisIsNotMyPwd myDatabase > /home/alepac/dumps/mydump.sql
    endscript
    postrotate
        rsync -avz --partial --delete /home/alepac/dumps/ my-remote-server.no-ip.biz:/home/alepac/db-backups/dbs/customer/ > /tmp/rsync.stdout 2> /tmp/rsync.stderr
    endscript
}

For better explaination, I'm rotating the dumps of a mysql database; I'm doing the dump on prerotate, then I rotate and sync the dump dir with remote machine using rsync on postrotate. Finally the create options makes a new zero sized dump to ensure next rotation.

Alepac
  • 101
  • 4

1 Answers1

0

The problem is caused by rsync. The postrotate script is executed before removing the old log files so in the remote location I always have the mydump.sql.11 file. Moreover if postscript fails (e.g. whene there is a network problem rsync will fail) then the remaining actions are not executed and so the logrotate doesn't remove mydump.sql.11 file.

Alepac
  • 101
  • 4