Compare commits

..

No commits in common. "130fe0258d50cd7ab2720d7f97060d4966844ae4" and "f17277ce8707497004fc90484e6ef83ca3a846e1" have entirely different histories.

5 changed files with 10 additions and 55 deletions

1
.gitignore vendored
View File

@ -1 +0,0 @@
.idea

View File

@ -1,11 +0,0 @@
[config]
# Used for authenticating the backup requests. Change to a random password, and keep the same on both the client and server.
BACKUP_KEY=supersecretkey
# Used for encrypting the backup files during transfer. Change to a random password, and keep the same on both the client and server.
CRYPTO_KEY=supersecretkey
# How often the client should backup in seconds. Default is 86400 seconds (24 hours).
BACKUP_INTERVAL=86400
# The URL of the server to send the backups to.
REMOTE_URL=http://example.org:8080
# The file to backup, relative to where the command is run.
FILE_LOCATION=/path/to/file

View File

@ -2,39 +2,20 @@ package main
import ( import (
"concord.hectabit.org/Hectabit/burgerbackup/lib/client" "concord.hectabit.org/Hectabit/burgerbackup/lib/client"
"github.com/spf13/viper"
"log" "log"
"os"
"strconv"
"time" "time"
) )
var (
backupKey = "meow"
backupInterval = 43200
fileLocation = "database.db"
remoteURL = "http://localhost:8088/api/backup"
)
func main() { func main() {
if _, err := os.Stat("config.ini"); err == nil {
log.Println("[INFO] Config loaded at", time.Now().Unix())
} else if os.IsNotExist(err) {
log.Fatalln("[FATAL] config.ini does not exist")
} else {
log.Fatalln("[FATAL] File is in quantum uncertainty:", err)
}
viper.SetConfigName("config")
viper.AddConfigPath("./")
viper.AutomaticEnv()
err := viper.ReadInConfig()
if err != nil {
log.Fatalln("[FATAL] Error in config file at", strconv.FormatInt(time.Now().Unix(), 10)+":", err)
}
backupKey := viper.GetString("BACKUP_KEY")
cryptoKey := viper.GetString("CRYPTO_KEY")
backupInterval := viper.GetInt("BACKUP_INTERVAL")
fileLocation := viper.GetString("FILE_LOCATION")
remoteURL := viper.GetString("REMOTE_URL")
for { for {
err, errCode := client.PerformBackup(fileLocation, backupKey, cryptoKey, remoteURL) err, errCode := client.PerformBackup(fileLocation, backupKey, remoteURL)
if err != nil { if err != nil {
if errCode == 0 { if errCode == 0 {
log.Println("[CRITICAL] Unknown in performBackup() file read:", err) log.Println("[CRITICAL] Unknown in performBackup() file read:", err)

View File

@ -1,12 +0,0 @@
[config]
# Used for authenticating the backup requests. Change to a random password, and keep the same on both the client and server.
BACKUP_KEY=supersecretkey
# Used for encrypting the backup files during transfer. Change to a random password, and keep the same on both the client and server.
CRYPTO_KEY=supersecretkey
# The port burgerbackup runs on. Change to Port 80 if not using a reverse proxy.
PORT=8080
# The host burgerbackup runs on. Change to 127.0.0.1 if using a reverse proxy.
HOST=0.0.0.0
# The folder where the backups are stored, relative to where the command is run.
# It is recommended to use an absolute path
BACKUP_FOLDER=/path/to/backup/folder

View File

@ -5,22 +5,20 @@ import (
"concord.hectabit.org/Hectabit/burgerbackup/lib/common" "concord.hectabit.org/Hectabit/burgerbackup/lib/common"
"encoding/json" "encoding/json"
"errors" "errors"
"golang.org/x/crypto/argon2"
"io" "io"
"log" "log"
"net/http" "net/http"
"os" "os"
) )
func PerformBackup(fileLocation string, backupKey string, cryptoKey string, remoteURL string) (error, int) { func PerformBackup(fileLocation string, backupKey string, remoteURL string) (error, int) {
fileContent, err := os.ReadFile(fileLocation) fileContent, err := os.ReadFile(fileLocation)
if err != nil { if err != nil {
log.Println("[CRITICAL] Unknown in performBackup() file read:", err) log.Println("[CRITICAL] Unknown in performBackup() file read:", err)
return err, 0 return err, 0
} }
cryptoKeyHashed := argon2.IDKey([]byte(cryptoKey), []byte("burgerbackup"), 1, 64*1024, 4, 32) encryptedContent, err := common.EncryptAES([]byte(backupKey), fileContent)
encryptedContent, err := common.EncryptAES(cryptoKeyHashed, fileContent)
if err != nil { if err != nil {
log.Println("[CRITICAL] Unknown in performBack() content encryption", err) log.Println("[CRITICAL] Unknown in performBack() content encryption", err)
return err, 1 return err, 1