-
-
Notifications
You must be signed in to change notification settings - Fork 908
/
Copy pathbackup.go
68 lines (57 loc) · 1.79 KB
/
backup.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
package core
import (
"os"
"path"
"strings"
"github.com/fatih/color"
"github.com/j3ssie/osmedeus/execution"
"github.com/j3ssie/osmedeus/libs"
"github.com/j3ssie/osmedeus/utils"
)
// in workflow file
// Compress('{{Backup}}/{{Workspace}}.tar.gz', '{{Output}}')
// Decompress('{{Output}}', '{{Backup}}/{{Workspace}}.tar.gz')
func (r *Runner) BackupWorkspace() {
utils.InforF("Backing up the workspace: %v", r.Target["Workspace"])
outputDir := r.Target["Output"]
dest := path.Join(r.Opt.Env.BackupFolder, r.Target["Workspace"]) + ".tar.gz"
if utils.FileExists(dest) {
os.Remove(dest)
}
execution.Compress(dest, outputDir)
if utils.FileExists(dest) {
utils.TSPrintF("Backup workspace save at %s", color.HiMagentaString(dest))
}
}
func CompressWorkspace(target string, opt libs.Options) {
utils.InforF("Backing up the workspace: %v", color.HiCyanString(target))
outputDir := path.Join(opt.Env.WorkspacesFolder, target)
if utils.FolderLength(outputDir) == 0 {
utils.ErrorF("Workspace is empty: %s", outputDir)
return
}
dest := path.Join(opt.Env.BackupFolder, target) + ".tar.gz"
if utils.FileExists(dest) {
os.Remove(dest)
}
execution.Compress(dest, outputDir)
if utils.FileExists(dest) {
utils.InforF("The workspace has been backed up and saved in %s", color.HiMagentaString(dest))
}
}
func ExtractBackup(src string, opt libs.Options) {
if !utils.FileExists(src) {
utils.ErrorF("Backup file not found: %s", src)
return
}
target := strings.ReplaceAll(path.Base(src), ".tar.gz", "")
dest := path.Join(opt.Report.ExtractFolder, target)
if !strings.HasSuffix(dest, "/") {
dest += "/"
}
if utils.FolderExists(dest) {
utils.MakeDir(dest)
}
execution.Decompress(dest, src)
utils.TSPrintF("Extracting the %v to %s", color.HiCyanString(target), color.HiMagentaString(dest))
}