A log folder with app.log, app.log.1, app.log.2.gz and so on gets crowded fast. I’d rather have the live file alone and the old copies somewhere else. logrotate has an option for that.
/var/log/myapp/*.log {
weekly
rotate 4
compress
missingok
olddir /var/log/myapp/old
createolddir 755 root root
}
With olddir, logs are moved into that directory for rotation, and all old versions end up there. A relative path is taken relative to the directory that holds the log file, and an absolute path is used as is.
The createolddir line creates the directory when it does not exist. It takes a mode and optionally an owner and group, and it assumes 0755 when you give no mode. If you leave that line out, create the directory yourself. nocreateolddir turns the creation off again.
Before it goes live, I’d test the file. The debug flag changes nothing and does not update the state file:
sudo logrotate -d /etc/logrotate.d/myapp
The caveat comes from the man page. The old directory must be on the same physical device as the log file being rotated, unless you use copy, copytruncate or renamecopy. If you want rotated logs on a bigger disk, add one of those. The noolddir option overrides olddir and rotates the logs in the directory where they normally live.
Further reading: logrotate(8) man page