How to move log files to a different folder using Logrotate

Move log files to a different folder using Logrotate.

With Logrotate, you can move log files to a different, specific folder. In our example below, we're using Nginx log files:

  1. Edit the logrotate configuration file:

     $ nano /etc/logrotate.d/nginx
  2. Use the olddir parameter and enter the full path to the new folder as the value:

     /var/log/nginx/*.log {
        ...
        olddir /var/log/nginx/newfolder_for_log
        ...
     }

    Logrotate configuration with olddir parameter to move log file to a different folder

    This will move the log files from /var/log/nginx/ over to /var/log/nginx/newfolder_for_log folder.

  3. Save the /etc/logrotate.d/nginx file changes.