Compare commits

..

2 Commits

5 changed files with 55 additions and 10 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
.idea

View File

@ -0,0 +1,11 @@
[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,20 +2,39 @@ package main
import (
"concord.hectabit.org/Hectabit/burgerbackup/lib/client"
"github.com/spf13/viper"
"log"
"os"
"strconv"
"time"
)
var (
backupKey = "meow"
backupInterval = 43200
fileLocation = "database.db"
remoteURL = "http://localhost:8088/api/backup"
)
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 {
err, errCode := client.PerformBackup(fileLocation, backupKey, remoteURL)
err, errCode := client.PerformBackup(fileLocation, backupKey, cryptoKey, remoteURL)
if err != nil {
if errCode == 0 {
log.Println("[CRITICAL] Unknown in performBackup() file read:", err)

View File

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