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.

4
  • Do you have current +10 or current +11 ?
    – user9517
    Commented Oct 23, 2014 at 7:47
  • @latin current +11, I edited the question for better understanding
    – Alepac
    Commented Oct 23, 2014 at 7:54
  • This doesn't seem to be a good way to do MySQL backups. Why are you reinventing the wheel? Commented Oct 23, 2014 at 12:53
  • @Michael could you suggest another way to do the same (save db dumps of last 10 days to a remote location with a bad connection)
    – Alepac
    Commented Oct 23, 2014 at 13:23

1 Answer 1

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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .