-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcore.go
75 lines (61 loc) · 1.69 KB
/
core.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
/******************************************************************************\
* Copyright (C) 2024-2024 The Molibackup Authors. All rights reserved. *
* Licensed under the Apache version 2.0 License *
* Homepage: https://github.com/fdupoux/molibackup *
\******************************************************************************/
package main
import (
"fmt"
)
type BackupModule interface {
LoadConfiguration(jobname string) error
InitialiseModule() error
CreateBackup() error
ListBackups() ([]BackupItem, error)
DeleteOldBackups([]BackupItem) error
}
type BackupItem struct {
identifier string
description string
timestamp int64
}
func runJob(jobname string) error {
var err error
var module BackupModule
jobconf, ok := jobmetadefs[jobname]
if ok == false {
return fmt.Errorf("configuration for job \"%s\" not found in the map", jobname)
}
switch jobconf.Module {
case "ebs-snapshot":
module = &backup_ebs_snapshot{}
default:
return fmt.Errorf("invalid type of backup module: \"%s\"", jobconf.Module)
}
// Load backup job configuration
err = module.LoadConfiguration(jobname)
if err != nil {
return fmt.Errorf("%w", err)
}
// Initialise the backup job
err = module.InitialiseModule()
if err != nil {
return fmt.Errorf("%w", err)
}
// Create a new backup
err = module.CreateBackup()
if err != nil {
return fmt.Errorf("%w", err)
}
// List existing backups
bkpitems, err := module.ListBackups()
if err != nil {
return fmt.Errorf("%w", err)
}
// Delete backups older than retention period
err = module.DeleteOldBackups(bkpitems)
if err != nil {
return fmt.Errorf("%w", err)
}
return nil
}