This repository has been archived by the owner on Dec 1, 2022. It is now read-only.
/
apt_spot_test_restore.go
86 lines (72 loc) · 2.46 KB
/
apt_spot_test_restore.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
package main
import (
"flag"
"fmt"
"github.com/APTrust/exchange/context"
"github.com/APTrust/exchange/models"
"github.com/APTrust/exchange/workers"
"os"
"time"
)
// 53687091200 = 50 GB
const MAX_FILE_SIZE = int64(53687091200)
const DAYS_SINCE_INGEST = 180
const DAYS_SINCE_LAST_RESTORE = 180
func main() {
pathToConfigFile, dryRun := parseCommandLine()
config, err := models.LoadConfigFile(pathToConfigFile)
if err != nil {
fmt.Fprintf(os.Stderr, err.Error())
os.Exit(1)
}
createdBefore := time.Now().UTC().AddDate(0, 0, (-1 * DAYS_SINCE_INGEST))
notRestoredSince := time.Now().UTC().AddDate(0, 0, (-1 * DAYS_SINCE_LAST_RESTORE))
_context := context.NewContext(config)
worker := workers.NewAPTSpotTestRestore(_context, MAX_FILE_SIZE, createdBefore, notRestoredSince)
worker.DryRun = dryRun
items, err := worker.Run()
if err != nil {
fmt.Fprintln(os.Stderr, "Error: ", err.Error())
} else {
printResults(items)
}
}
func printResults(items []*models.WorkItem) {
fmt.Println("Created Restore WorkItems for the following intellectual objects:")
for _, item := range items {
fmt.Println(item.ObjectIdentifier)
}
}
// See if you can figure out from the function name what this does.
func parseCommandLine() (string, bool) {
var pathToConfigFile string
dryRun := flag.Bool("dryrun", false, "List which bags would be chosen, but don't queue any WorkItems")
flag.StringVar(&pathToConfigFile, "config", "", "Path to APTrust config file")
flag.Parse()
if pathToConfigFile == "" {
printUsage()
os.Exit(1)
}
return pathToConfigFile, *dryRun
}
// Tell the user about the program.
func printUsage() {
message := `
apt_spot_test_restore selects one bag from each institution to restore, so that
APTrust and its depositors can see that bag restoration is working properly.
After selecting a bag, this app creates a Restore WorkItem in Pharos for the
bag. From there, it follows the normal restoration process.
The restorer chooses the first bag from each institution that meets the
following criteria:
* Bag is less than 20 GB in size.
* Bag was ingested at least 180 days ago.
* Bag has not been restored in the past 180 days.
Usage:
apt_spot_test_restore -config=<absolute path to APTrust config file>
apt_spot_test_restore -config=<absolute path to APTrust config file> -dryrun
Param -config is required.
If param -dryrun is present, the program will return a list of bags that would be
queued for restoration, but it won't actually queue them.
`
fmt.Println(message)
}