ยง2024-07-10

Nextcloud logs can be rotated, but it depends on your configuration. By default, Nextcloud does not automatically rotate its logs. However, you can set up log rotation using tools like logrotate on your server.

Here's how you can set up log rotation for nextcloud.log using logrotate:

Create a Logrotate Configuration File:

Create a file in the /etc/logrotate.d/ directory, for example, nextcloud:

  1. edit /etc/logrotate.d/nextcloud as,
/var/www/nextcloud/data/nextcloud.log {
    su www-data www-data
    daily
    missingok
    rotate 14
    compress
    delaycompress
    notifempty
    create 640 www-data www-data
    sharedscripts
    postrotate
        /usr/bin/php /var/www/nextcloud/occ log:rotate --size=10M
    endscript
}

  1. Reload Logrotate:

After creating the configuration file, reload logrotate to apply the changes:

suroot@hc4Bookworm:/var/www/nextcloud/data# /sbin/logrotate -f /etc/logrotate.d/nextcloud
error: skipping "/var/www/nextcloud/data/nextcloud.log" because parent directory has insecure permissions (It's world writable or writable by group which is not "root") Set "su" directive in config file to tell logrotate which user/group should be used for rotation.
/sbin/logrotate -f /etc/logrotate.d/nextcloud
error: /etc/logrotate.d/nextcloud:15 unexpected }
An unhandled exception has been thrown:
OCP\HintException: [0]: Memcache OC\Memcache\APCu not available for local cache (Is the matching PHP module installed and enabled?)
error: error running shared postrotate script for '/var/www/nextcloud/data/nextcloud.log '
sudo apt update
sudo apt install php-apcu
sudo phpenmod apcu
sudo systemctl restart apache2   # For Apache
sudo systemctl restart nginx     # For Nginx

/sbin/logrotate -f /etc/logrotate.d/nextcloud

By setting up log rotation with logrotate, you ensure that your Nextcloud logs do not grow indefinitely and are managed effectively. Make sure to adjust the file paths and permissions as per your server setup.


---

ls -l /var/www/

total 237124 drwxr-xr-x 2 root root 49 Jul 8 10:55 html drwxr-xr-x 14 www-data www-data 4096 Jul 9 15:17 nextcloud <-- -rw-r--r-- 1 root root 242806926 Jul 8 10:56 nextcloud.zip root@hc4Bookworm:# ls -l /var/www/nextcloud total 1212 drwxr-xr-x 44 www-data www-data 4096 Jun 25 18:02 3rdparty drwxr-xr-x 57 www-data www-data 4096 Jul 9 17:36 apps -rw-r--r-- 1 www-data www-data 23796 Jun 25 17:58 AUTHORS -rw-r--r-- 1 www-data www-data 2079 Jun 25 17:58 composer.json -rw-r--r-- 1 www-data www-data 3140 Jun 25 17:58 composer.lock drwxr-xr-x 2 www-data www-data 120 Jul 9 16:22 config -rw-r--r-- 1 www-data www-data 4145 Jun 25 17:58 console.php -rw-r--r-- 1 www-data www-data 34520 Jun 25 17:58 COPYING drwxr-xr-x 24 www-data www-data 4096 Jun 25 18:02 core -rw-r--r-- 1 www-data www-data 8461 Jun 25 17:58 cron.php drwxrwx--- 6 www-data www-data 4096 Jul 9 12:43 data <--- drwxr-xr-x 2 www-data www-data 12288 Jun 25 17:58 dist -rw-r--r-- 1 www-data www-data 156 Jun 25 17:58 index.html -rw-r--r-- 1 www-data www-data 4564 Jun 25 17:58 index.php drwxr-xr-x 6 www-data www-data 125 Jun 25 17:58 lib -rw-r--r-- 1 www-data www-data 283 Jun 25 17:58 occ drwxr-xr-x 2 www-data www-data 55 Jun 25 17:58 ocs drwxr-xr-x 2 www-data www-data 23 Jun 25 17:58 ocs-provider -rw-r--r-- 1 www-data www-data 6999 Jun 25 17:58 package.json -rw-r--r-- 1 www-data www-data 1067179 Jun 25 17:58 package-lock.json -rw-r--r-- 1 www-data www-data 3759 Jun 25 17:58 public.php -rw-r--r-- 1 www-data www-data 5597 Jun 25 17:58 remote.php drwxr-xr-x 4 www-data www-data 133 Jun 25 17:58 resources -rw-r--r-- 1 www-data www-data 26 Jun 25 17:58 robots.txt -rw-r--r-- 1 www-data www-data 2523 Jun 25 17:58 status.php drwxr-xr-x 3 www-data www-data 35 Jun 25 17:58 themes drwxr-xr-x 2 www-data www-data 43 Jun 25 17:59 updater -rw-r--r-- 1 www-data www-data 383 Jun 25 18:02 version.php root@hc4Bookworm:# ls -l /var/www/nextcloud/data total 1160 drwxr-xr-x 7 www-data www-data 91 Jul 8 13:19 alexlai drwxr-xr-x 13 www-data www-data 171 Jul 9 18:08 appdata_oc5kx4u32hmz -rw-r--r-- 1 www-data www-data 0 Jul 8 18:16 audit.log drwxr-xr-x 2 www-data www-data 27 Jul 8 12:57 files_external -rw-r--r-- 1 root root 580490 Jul 9 12:44 filtered_errors.log -rw-r--r-- 1 www-data www-data 0 Jul 8 12:56 index.html drwxr-xr-x 4 www-data www-data 32 Jul 8 14:07 nextCloudAdmin -rw-r----- 1 www-data www-data 601006 Jul 9 17:51 nextcloud.log <---