mirror of
https://github.com/ClusterCockpit/cc-backend
synced 2024-12-24 12:29:05 +01:00
Add clean functionality to archive manager
This commit is contained in:
parent
1ae34c5e10
commit
6731b8b1e0
@ -9,12 +9,28 @@ import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"github.com/ClusterCockpit/cc-backend/internal/config"
|
||||
"github.com/ClusterCockpit/cc-backend/pkg/archive"
|
||||
"github.com/ClusterCockpit/cc-backend/pkg/log"
|
||||
)
|
||||
|
||||
func parseDate(in string) int64 {
|
||||
const shortForm = "2006-Jan-02"
|
||||
loc, _ := time.LoadLocation("Local")
|
||||
if in != "" {
|
||||
t, err := time.ParseInLocation(shortForm, in, loc)
|
||||
if err != nil {
|
||||
fmt.Printf("date parse error %v", err)
|
||||
os.Exit(0)
|
||||
}
|
||||
return t.Unix()
|
||||
}
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
func main() {
|
||||
var srcPath, flagConfigFile, flagLogLevel, flagRemoveCluster, flagRemoveAfter, flagRemoveBefore string
|
||||
var flagLogDateTime, flagValidate bool
|
||||
@ -24,8 +40,8 @@ func main() {
|
||||
flag.StringVar(&flagLogLevel, "loglevel", "warn", "Sets the logging level: `[debug,info,warn (default),err,fatal,crit]`")
|
||||
flag.StringVar(&flagConfigFile, "config", "./config.json", "Specify alternative path to `config.json`")
|
||||
flag.StringVar(&flagRemoveCluster, "remove-cluster", "", "Remove cluster from archive and database")
|
||||
flag.StringVar(&flagRemoveBefore, "remove-before", "", "Remove all jobs with start time before date")
|
||||
flag.StringVar(&flagRemoveAfter, "remove-after", "", "Remove all jobs with start time after date")
|
||||
flag.StringVar(&flagRemoveBefore, "remove-before", "", "Remove all jobs with start time before date (Format: 2006-Jan-04)")
|
||||
flag.StringVar(&flagRemoveAfter, "remove-after", "", "Remove all jobs with start time after date (Format: 2006-Jan-04)")
|
||||
flag.BoolVar(&flagValidate, "validate", false, "Set this flag to validate a job archive against the json schema")
|
||||
flag.Parse()
|
||||
|
||||
@ -47,5 +63,10 @@ func main() {
|
||||
os.Exit(0)
|
||||
}
|
||||
|
||||
if flagRemoveBefore != "" || flagRemoveAfter != "" {
|
||||
ar.Clean(parseDate(flagRemoveBefore), parseDate(flagRemoveAfter))
|
||||
os.Exit(0)
|
||||
}
|
||||
|
||||
ar.Info()
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user