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:
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user