[syslog-ng]Rotate my logs files
Russell Adams
syslog-ng@lists.balabit.hu
Mon, 2 Jun 2003 08:40:42 -0500
--opJtzjQTFsWo+cga
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
I use a similar directory hierarchy for my logs, and use the attached
script to make a monthly archive of old logs.
I run this once a month on the first, and it tars all log files over 3
months old to /var/log/archive/ . It removes any log files that it
archives, cleans up any .offset files left by logtail, and prunes any
empty directories out of the hierarchy.
I hope you find it useful.
Russell
On Mon, Jun 02, 2003 at 11:58:20AM +0200, Jens Grigel wrote:
> Am Don, 2003-05-29 um 13.38 schrieb Moktar KONE:
> > Hi ,
> > I am testing syslog-ng and I want to know how can I rotate my logs file .
> > To logs messages I have a directory for many hosts, for each host, logs are
> > classified by facilities, I have a new log file each day for each facility.
> > so the name of my logs files changes according to the date.
> > how can rotate the old log files? the logs of 2days ago? 3days ago?
> > thanks
> > this is the section that logs my files :
> > destination hosts {
> >
> > file("/var/log/HOSTS/$HOST/$FACILITY/$FACILITY_$YEAR_$MONTH_$DAY"
> > create_dirs(yes));
> > };
> >
>
> Hi,
>
> you probably want to compress the logs:
>
> I'm calling a very short shell script through cron,
> should be like this for your setup:
>
> #!/bin/bash
> #
> # compress old syslog-ng logs
> #
> # date from day before yesterday
> date2comp=`date -d "2 days ago" +%Y_%m_%d
> # use find to compress the logs
> find /var/log/HOSTS -name "*_$date2comp" -exec bzip2 {} \;
>
> HTH,
> Jens
>
> _______________________________________________
> syslog-ng maillist - syslog-ng@lists.balabit.hu
> https://lists.balabit.hu/mailman/listinfo/syslog-ng
> Frequently asked questions at http://www.campin.net/syslog-ng/faq.html
--opJtzjQTFsWo+cga
Content-Type: application/x-sh
Content-Disposition: attachment; filename="archive_logs.sh"
Content-Transfer-Encoding: quoted-printable
#!/bin/sh=0A=0A# If TIMEWARP isn't already defined, it should be -3 months=
=0ATIMEWARP=3D${TIMEWARP:-"-3 months"}=0A=0A# Get date strings=0AYEAR=3D`/b=
in/date -d "${TIMEWARP}" "+%Y"`=0AMONTH=3D`/bin/date -d "${TIMEWARP}" "+%m"=
`=0A=0A# TAR from a relative path=0Acd /var/log/HOSTS=0A=0A# Backup all log=
files (not offset files) to a monthly tar=0A/bin/tar --exclude=3D\*.offset=
--remove-files \=0A -zcvf /var/log/archive/syslog_${YEAR}_${MONTH}.tar.=
gz \=0A */${YEAR}/${MONTH}/*/*=0A=0A# Ensure perms=0A=0A/bin/chmod 400 /=
var/log/archive/*=0A=0A# Remove all offset files=0A/bin/rm -rf /var/log/HOS=
TS/*/${YEAR}/${MONTH}/*/*.offset=0A=0A# Get rid of empty directories, three=
levels deep=0A/usr/bin/find /var/log/HOSTS/ -type d -empty -mtime -90 | \=
=0A xargs -trn1 /bin/rmdir=0A/usr/bin/find /var/log/HOSTS/ -type d -empt=
y -mtime -90 | \=0A xargs -trn1 /bin/rmdir=0A/usr/bin/find /var/log/HOST=
S/ -type d -empty -mtime -90 | \=0A xargs -trn1 /bin/rmdir=0A
--opJtzjQTFsWo+cga--