Backups feature

This commit is contained in:
Paulo Truta
2023-05-29 21:52:27 +02:00
parent f7823b9e20
commit a66ff40e65
5 changed files with 315 additions and 7 deletions
+16 -3
View File
@@ -16,7 +16,7 @@ import (
)
// ExecAndStream : Runs a terminal command, but streams progress instead of outputting. Ideal for long lived process that need to be logged.
func ExecAndStream(path string, command string, args []string) {
func ExecAndStream(path string, command string, args []string) string {
cmd := exec.Command(command, args...)
@@ -27,13 +27,17 @@ func ExecAndStream(path string, command string, args []string) {
err := cmd.Run()
outStr, errStr := string(stdoutBuf.Bytes()), string(stderrBuf.Bytes())
returnVal := outStr
if err != nil {
fmt.Printf("cmd.Run() failed with %s\n", err)
returnVal = errStr
}
outStr, errStr := string(stdoutBuf.Bytes()), string(stderrBuf.Bytes())
fmt.Printf("\nout:\n%s\nerr:\n%s\n", outStr, errStr)
return returnVal
}
// Exec : Runs a terminal Command, catches and logs errors, returns the result.
@@ -100,6 +104,7 @@ func GetSQLiteFormattedDateTime(t time.Time) string {
return formatedDatetime
}
const BackupPasswordFileLocation string = "backupPasswordFileLocation"
const CloudEnvFileLocation string = "cloudEnvFileLocation"
const ApiEnvFileLocation string = "apiEnvFileLocation"
const ApiPath string = "apiPath"
@@ -159,6 +164,14 @@ func GetPath(pathKey string) string {
targetPath = "/home/system/components/ws/"
}
case BackupPasswordFileLocation:
if env["BACKUP_PASSWORD_FILE_LOCATION"] != "" {
targetPath = env["BACKUP_PASSWORD_FILE_LOCATION"]
} else {
targetPath = "/home/system/components/backups/pw.txt"
}
default:
log.Printf("path_key %s nonexistant in GetPath().\n", pathKey)
@@ -207,7 +220,7 @@ func ReadOption(optionKey string) string {
err = db.QueryRow("SELECT value FROM option WHERE name = ?", optionKey).Scan(&optionValue)
if err != nil {
log.Fatal(err.Error())
log.Println(err.Error())
}
db.Close()