newsyslog: moving old logs to a directory

Colleagues, please tell me, is it possible to configure newsyslog so that it automatically transfers old, compressed fragments of log files to a separate directory or directories? And there he rotated them.

For a number of reasons, I have to store old files for a fairly long period in the directory with nginx logs. There are quite a lot of virtual sites, each one writes at least two files. Even finding the required log in /var/log/nginx is not very easy. Is it possible to remove, for example, old files in /var/log/nginx/backup, but retain the functionality of rotating them?

Thanks in advance for your recommendations,
Ogogon.
 
newsyslog(8)

Are you looking for this?

Code:
-a directory
           Specify a directory into    which archived log files will be writ-
           ten.   If  a relative path is given, it is appended to the path
           of each log file    and the    resulting path is used as  the    direc-
           tory  into  which  the  archived     log for that log file will be
           written.     If an absolute    path is    given, all archived  logs  are
           written into the    given directory.  If any component of the path
           directory  does not exist, it will be created when newsyslog is
           run.
 
newsyslog.conf(8)

Are you looking for this?

Code:
-a directory
           Specify a directory into    which archived log files will be writ-
           ten.   If  a relative path is given, it is appended to the path
           of each log file    and the    resulting path is used as  the    direc-
           tory  into  which  the  archived     log for that log file will be
           written.     If an absolute    path is    given, all archived  logs  are
           written into the    given directory.  If any component of the path
           directory  does not exist, it will be created when newsyslog is
           run.
I think you meant newsyslog(8). For newsyslog.conf manuals is absent.
In accordance with the manual, I added the following line to /etc/rc.conf:
Code:
newsyslog_flags="-CN -a archive"
I waited for newsyslog to start, then, just to be safe, I ran it through /etc/rc.d/newsyslog a few times.
The result is completely zero - the directory was not created, the old files, of course, were not moved.
Either I'm doing something wrong, or this option doesn't work.
 
Yes i meant the newsyslog manual. The newsyslog.conf is in file format manual 5 aka newsyslog.conf(5)

Fixed in my first post.

It depend how your rotation is configured. You can test the log file rotation via this example:

mkdir /var/log/archive
newsyslog -nv -a /var/log/archive
It will only print what will going to happen without actually rotate or move any files. All new archived log files will be put into /var/log/archive/instead of they original location next to the log files. If you are happy with the result you can force the log rotation with
newsyslog -F -a /var/log/archive

Do not put -N flag in your /etc/rc.conf this will prevent newsyslog to work as this flag is intended to be used only when you want to create the empty log files manually with -C
 
Back
Top