rrgc
🗑 round-robin garbage-collector
n


Usage
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 | 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:~$ rrgc 24h,5 1h,5 -- ./logs/*.log
foo@bar:~$ ls logs
A.log
D.log
F.log
G.log
I.log
J.log
K.log
L.log
As a Library
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".
Install
Using go
go get moul.io/rrgc
Releases
See https://github.com/moul/rrgc/releases
Contribute

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
Dev helpers
Pre-commit script for install: https://pre-commit.com
Contributors ✨

Thanks goes to these wonderful people (emoji key):
This project follows the all-contributors
specification. Contributions of any kind welcome!
Stargazers over time

License
© 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)