rrgc

command module
Version: v1.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 4, 2021 License: Apache-2.0, MIT Imports: 12 Imported by: 0

README

rrgc

🗑 round-robin garbage-collector

go.dev reference License GitHub release Docker Metrics Made by Manfred Touron n Go Release PR GolangCI codecov Go Report Card CodeFactor

Gitpod ready-to-code

Usage

As a CLI tool
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 ✨

All Contributors

Thanks goes to these wonderful people (emoji key):


Manfred Touron

🚧 📖 ⚠️ 💻

moul-bot

🚧

This project follows the all-contributors specification. Contributions of any kind welcome!

Stargazers over time

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)

Documentation

Overview

message from the author:

+--------------------------------------------------------------+
| * * * ░░░░░░░░░░░░░░░░░░░░  Hello  ░░░░░░░░░░░░░░░░░░░░░░░░░░|
+--------------------------------------------------------------+
|                                                              |
|     ++              ______________________________________   |
|     ++++           /                                      \  |
|      ++++          |                                      |  |
|    ++++++++++      |   Feel free to contribute to this    |  |
|   +++       |      |       project or contact me on       |  |
|   ++         |     |    manfred.life if you like this     |  |
|   +  -==   ==|     |               project!               |  |
|  (   <*>   <*>     |                                      |  |
|   |          |    /|                  :)                  |  |
|   |         _)   / |                                      |  |
|   |      +++    /  \______________________________________/  |
|    \      =+   /                                             |
|     \      +                                                 |
|     |\++++++                                                 |
|     |  ++++      ||//                                        |
|  ___|   |___    _||/__                                     __|
| /    ---    \   \|  |||                   __ _  ___  __ __/ /|
|/  |       |  \    \ /                    /  ' \/ _ \/ // / / |
||  |       |  |    | |                   /_/_/_/\___/\_,_/_/  |
+--------------------------------------------------------------+

Source Files

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL