Rotate logs manually (nextcloud.log audit.log)

Is possible to force a manual rotation of logs with occ or similar command?

I’ve configured a log_size_rotation parameter but I would like to perform a manual rotation with some other operation on a daily basis (compression, renaming…)

Stop php and webserver. MV the logfiles and add any ending, like: .log.1

assuming you are running apache:

sudo -u www-data touch nextcloud.log

Make sure log_rotate_size is set to 0 in config.php to disable logrotation handling by Nextcloud.
https://docs.nextcloud.com/server/stable/admin_manual/configuration_server/config_sample_php_parameters.html

If not I’ve found a solution using linux native command logrotate that also performs some other operations (compress, relabel…)

you can just add a new conf to /etc/logrotate.d/nextcloud-audit like this

/xxxxxxx/nextcloud_logs/audit.log {
        su www-data www-data
        daily 
        missingok
        rotate 365
        copytruncate
        compress
        notifempty
        dateext
        dateformat -%Y%m%d%H%M%S
        lastaction
            /bin/mv /xxxxx/nextcloud_logs/audit.log*.gz /xxxxxx/archive/
        endscript
}

to test → logrotate -d /etc/logrotate.d/nextcloud-audit
to force → logrotate --force /etc/logrotate.d/nextcloud-audit

thanks @Kerasit and @tcit for your suggestions but my latest solution allows to perform this operation without having to stop server.

Regards