Skip to content

Commit 182f196

Browse files
committed
γ€ŒπŸ”¨γ€ fix: fixed issue with rebooting
1 parent bac0266 commit 182f196

3 files changed

Lines changed: 14 additions & 25 deletions

File tree

β€Ž.gitignoreβ€Ž

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#*/.env
2-
#.env
3-
41
.direnv
5-
#secrets/
2+
3+
docker-compose.yml

β€Žsrcs/Dockerfileβ€Ž

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM alpine:3.21 AS builder
1+
FROM alpine:3.22 AS builder
22

33
RUN apk add go
44

@@ -13,7 +13,7 @@ RUN cd /build \
1313
&& go build git.keyzox.me/42_adjoly/inception/cmd/borg-backup/entrypoint \
1414
&& go build git.keyzox.me/42_adjoly/inception/cmd/borg-backup/getpassphrase
1515

16-
FROM alpine:3.21
16+
FROM alpine:3.22
1717

1818
LABEL version="0.1"
1919
LABEL maintainer="KeyZox"

β€Žsrcs/cmd/borg-backup/entrypoint/entrypoint.goβ€Ž

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -30,19 +30,12 @@ func overrideCronFile(filePath string, jobs []string) error {
3030
return writer.Flush()
3131
}
3232

33-
func isBorgInit(repo string) (bool, error) {
34-
cmd := exec.Command("borg", "info", repo)
35-
36-
err := cmd.Run()
37-
if err != nil {
38-
if exitError, ok := err.(*exec.ExitError); ok {
39-
if exitError.ExitCode() == 2 {
40-
return false, nil
41-
}
42-
}
43-
return false, err
33+
func isBorgInit(repo string) bool {
34+
dir, err := os.ReadDir(repo)
35+
if err != nil || len(dir) == 0 {
36+
return false
4437
}
45-
return true, err
38+
return true
4639
}
4740

4841
func main() {
@@ -57,10 +50,8 @@ func main() {
5750
if _, err := os.ReadDir(src); err != nil {
5851
_log.Log("error", repo+" does not exist can't perform backup")
5952
}
60-
is, err := isBorgInit(repo)
61-
if err != nil {
62-
log.Fatal(err)
63-
} else if is == true {
53+
is := isBorgInit(repo)
54+
if is == true {
6455
_log.Log("note", "Repo already initialize, skipping...")
6556
} else {
6657
_log.Log("note", "Initializing repo...")
@@ -70,7 +61,7 @@ func main() {
7061
_log.Log("error", "No passphrase specified, exiting...")
7162
}
7263

73-
err = cmd.ExecCmd([]string{"borg", "init", "--encryption=repokey-blake2", repo}, slices.Insert(os.Environ(), len(os.Environ()), "BORG_PASSPHRASE="+passphrase))
64+
err := cmd.ExecCmd([]string{"borg", "init", "--encryption=repokey-blake2", repo}, slices.Insert(os.Environ(), len(os.Environ()), "BORG_PASSPHRASE="+passphrase))
7465
if err != nil {
7566
log.Fatal(err)
7667
}
@@ -80,9 +71,9 @@ func main() {
8071
cronFilePath := "/etc/crontabs/root"
8172
newJobs := []string{
8273
"# Borg Backup Cron Job",
83-
interval + " root run-parts /docker-backup.d >> /var/log/cron.log 2>&1",
74+
interval + " run-parts /docker-backup.d >> /var/log/cron.log 2>&1",
8475
}
85-
err = overrideCronFile(cronFilePath, newJobs)
76+
err := overrideCronFile(cronFilePath, newJobs)
8677
if err != nil {
8778
fmt.Printf("Error overriding cron file: %v\n", err)
8879
} else {

0 commit comments

Comments
Β (0)