updates to backups directory (#1099)

* read BackupDirectory from command line flag

* Change the default backup directory

* mkdir BackupDirectory

* use config for backup file path

* migrateDatabase to the backup directory

* use DoesFileExists

change permission on the directory to 0700

* declare err

* generate backupFile  where needed

* style fix

* more style fixes

* more style fixes
This commit is contained in:
Meisam
2021-06-14 00:28:59 +02:00
committed by GitHub
parent d9a6be2ac6
commit e991199735
4 changed files with 22 additions and 4 deletions

View File

@@ -8,15 +8,16 @@ import (
"database/sql"
"fmt"
"os"
"path/filepath"
"time"
"github.com/owncast/owncast/config"
"github.com/owncast/owncast/utils"
log "github.com/sirupsen/logrus"
)
const (
schemaVersion = 0
backupFile = "backup/owncastdb.bak"
)
var _db *sql.DB
@@ -95,6 +96,7 @@ func SetupPersistence(file string) error {
dbBackupTicker := time.NewTicker(1 * time.Hour)
go func() {
backupFile := filepath.Join(config.BackupDirectory, "owncastdb.bak")
for range dbBackupTicker.C {
utils.Backup(_db, backupFile)
}
@@ -105,7 +107,8 @@ func SetupPersistence(file string) error {
func migrateDatabase(db *sql.DB, from, to int) error {
log.Printf("Migrating database from version %d to %d\n", from, to)
utils.Backup(db, fmt.Sprintf("backup/owncast-v%d.bak", from))
dbBackupFile := filepath.Join(config.BackupDirectory, fmt.Sprintf("owncast-v%d.bak", from))
utils.Backup(db, dbBackupFile)
for v := from; v < to; v++ {
switch v {
case 0: