Oliver Gorwits


  yatg-trim - A trim script to delete old data from yatg files.



FILENAME is a YATG::Store::Disk generated file containing polling data. PERIOD is the amount of historical data you wish to lose. It can be in seconds (e.g. "5"), minutes (e.g. "5m"), hours (e.g. "5h") or days (e.g. "5d").

  yatg-trim,300 5d
  yatg-trim /var/lib/yatg/,300
  yatg-trim --verbose /var/lib/yatg/,300

Options allow you to specify the level of output, be it "--quiet", "--debug" or "--verbose"


This script takes one yatg file, and removes the bottom (i.e. oldest) polls from that file. YATG itself will read the most recent file in the directory so in theory the newly generated file will be in use as soon as it is created, and the two can live side-by-side. In practice you will probably want to delete the old file after the script has run.

Running the script iteratively

This script only runs on one file at a time. Used in conjunction with find though an iterative effect can be achived, particularly since the filename holds the data on how much information should be in the file.

    find /var/lib/yatg -type f -name '2011*' -print -exec yatg-trim {} 365d \;

This will take all files that have been around for over a year and trim a year's worth of data from it.

If you are sure this script is fine to delete the old file and clear up space as you go you can live dangerously

    find /var/lib/yatg -type f -name '2011*' -print -exec yatg-trim {} 365d \; -delete

Be warned that the examples above assume that filenames starting in 2011 are of a format consistent with yatg filenames. If not, yatg-trim will emit an error.


This script is a very small script to free up space on servers at Oxford University IT Services. It filled that need, but I feel it my duty to point out certain caveats

Race condition

The script can potentially cause a race condition where YATG can write to the file as it is being trimmed. You will lose that particular poll.


This script is not meant to be run often and as such there has been no accounting for the speed at which it runs.


There has only been minor consideration of operating systems other than *nix based ones. This script may run on other OSes, but it may not.

Portability (again).

This script assumes that the backend storage for YATG::Store::Disk remains newline delimited. If that ever changes, then this script will need to be altered to accommodate it (by altering $/).


Christopher Causer <networks@it.ox.ac.uk>


This script is free software; you can redistribute it and/or modify it under the same terms as defined in YATG.