NAME
yatg-trim - A trim script to delete old data from yatg files.
SYNOPSIS
yatg-trim [OPTIONS] FILENAME [PERIOD]
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 192.168.56.1/ifHCOutOctets/Vlan42/2011-09-13_12-45-00Z,300 5d
yatg-trim /var/lib/yatg/10.10.6.1/ifHCOutOctets/Vlan42/2011-09-13_12-45-00Z,300
yatg-trim --verbose /var/lib/yatg/10.10.6.1/ifHCOutOctets/Vlan42/2011-09-13_12-45-00Z,300
Options allow you to specify the level of output, be it "--quiet", "--debug" or "--verbose"
DESCRIPTION
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.
BUGS AND CAVEATS
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.
- Speed
-
This script is not meant to be run often and as such there has been no accounting for the speed at which it runs.
- Portability
-
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 $/).
AUTHOR
Christopher Causer <networks@it.ox.ac.uk>
COPYRIGHT AND LICENCE
This script is free software; you can redistribute it and/or modify it under the same terms as defined in YATG.