π round-robin garbage-collector
foo@bar:~$ rrgc -h
USAGE
rrgc WINDOWS -- GLOBS
FLAGS
-debug false debug
-keep false print list of files to keep instead of files to delete
foo@bar:~$ ls logs
A.log
B.log
C.log
D.log
E.log
F.log
G.log
H.log
I.log
J.log
K.log
L.log
M.log
N.log
O.log
P.log
Q.log
R.log
foo@bar:~$ rrgc 24h,5 1h,5 -- ./logs/*.log
logs/B.log
logs/C.log
logs/E.log
logs/H.log
logs/M.log
logs/N.log
logs/O.log
logs/P.log
logs/Q.log
logs/R.log
foo@bar:~$ rrgc --keep 24h,5 1h,5 -- ./logs/*.log
logs/A.log
logs/D.log
logs/F.log
logs/G.log
logs/I.log
logs/J.log
logs/K.log
logs/L.log
foo@bar:~$ rrgc 24h,5 1h,5 -- ./logs/*.log | xargs rm -v
removed 'logs/B.log'
removed 'logs/C.log'
removed 'logs/E.log'
removed 'logs/H.log'
removed 'logs/M.log'
removed 'logs/N.log'
removed 'logs/O.log'
removed 'logs/P.log'
removed 'logs/Q.log'
removed 'logs/R.log'
foo@bar:~$ ls logs
A.log
D.log
F.log
G.log
I.log
J.log
K.log
L.log
import (
"os"
"time"
"moul.io/rrgc/rrgc"
)
func Example() {
logGlobs := []string{
"*/*.log",
"*/*.log.gz",
}
windows := []rrgc.Window{
{Every: 2 * time.Hour, MaxKeep: 5},
{Every: time.Hour * 24, MaxKeep: 4},
{Every: time.Hour * 24 * 7, MaxKeep: 3},
}
_, toDelete, _ := rrgc.GCListByPathGlobs(logGlobs, windows)
for _, path := range toDelete {
_ = os.Remove(path)
}
}
FUNCTIONS
func GCListByPathGlobs(inputs []string, windows []Window) ([]string, []string, error)
GCListByPathGlobs computes a list of paths that should be kept and deleted,
based on a list of window rules.
TYPES
type Window struct {
Every time.Duration
MaxKeep int
}
Window defines a file preservation rule.
func ParseWindow(input string) (Window, error)
ParseWindow parses a human-readable Window definition.
Syntax: "Duration,MaxKeep".
Examples: "1h,5" "1h2m3s,42".
go get moul.io/rrgc
See https://github.com/moul/rrgc/releases
I really welcome contributions. Your input is the most precious material. I'm well aware of that and I thank you in advance. Everyone is encouraged to look at what they can do on their own scale; no effort is too small.
Everything on contribution is sum up here: CONTRIBUTING.md
Pre-commit script for install: https://pre-commit.com
Thanks goes to these wonderful people (emoji key):
Manfred Touron π§ π |
moul-bot π§ |
This project follows the all-contributors specification. Contributions of any kind welcome!
Β© 2021 Manfred Touron
Licensed under the Apache License, Version 2.0
(LICENSE-APACHE
) or the MIT license
(LICENSE-MIT
), at your option.
See the COPYRIGHT
file for more details.
SPDX-License-Identifier: (Apache-2.0 OR MIT)