Skip to content
/ keep Public

Keep files by date or remove them. Think of backup files to be saved for a certain amount of hours, days, weeks, months, or years.

License

Notifications You must be signed in to change notification settings

jojomi/keep

Repository files navigation

keep

Godoc Reference Go Version Last Commit Coverage Go Report Card License

This library helps you decide which elements should be kept for a given number of hours, days, weeks, months, and years. Most obvious use case are backup files.

Installation

CLI tool keep

go install github.com/jojomi/keep/command/keep@latest

Golang library keep

go get github.com/jojomi/keep

Algorithm

Given the configuration below (3 last, 12 hours, 7 days, 12 weeks, 12 months, and 4 years) this library will operate on the list of elements sorted by date, youngest first.

  • It will select the first 3 elements from the list (last)
  • It then will select 12 elements that are not more than an hour apart (plus one minute extended range), the first of them being the youngest file not yet processed in the set.
  • It will then select 7 elements that are not less than a day (plus one hour) apart, the first of them being the youngest file not yet processed in the set.
  • and so on as far as levels are defined.
  • It is allowed to skip definitions, so you don't have to select daily elements even if you specify hourly and weekly selections.

Usage

import "github.com/jojomi/keep"

func main() {
    j := NewDefaultJailhouse()
    j.AddElements(...)

    reqs := NewRequirementsFromMap(map[TimeRange]uint16{
        LAST: 3,
        DAY:  2,
        MONTH: 4,
    })

    j.ApplyRequirements(*reqs)
    kept := j.KeptElements()
    deletable := j.FreeElements()

    // print kept elements
    for _, k := range kept {
        // handle here
    }
	
    // delete now
    for _, k := range deletable {
        // handle here
    }
}

Your input data must implement the TimeResource interface:

type TimeResource interface {
	GetTime() time.Time
}

Development

Add git hooks:

git config --local core.hooksPath .githooks/

About

Keep files by date or remove them. Think of backup files to be saved for a certain amount of hours, days, weeks, months, or years.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •