Take control over your live stream video by running it yourself. Streaming + chat out of the box.
HTML activitypubbroadcastingchatdecentralizedfederationfediversegolanghacktoberfesthlslivelivestreamowncastrtmpself-hostedstreaming-videovideo
updates to backups directory (#1099)
Meisam1454cb1b0e59
diff --git a/config/constants.go b/config/constants.goindex 6008aeed10..09f0b9954a 100644--- a/config/constants.go+++ b/config/constants.go@@ -11,8 +11,6 @@ const (PrivateHLSStoragePath = "hls"// FfmpegSuggestedVersion is the version of ffmpeg we suggest.FfmpegSuggestedVersion = "v4.1.5" // Requires the v- // BackupDirectory is the directory we write backup files to.- BackupDirectory = "backup"// DataDirectory is the directory we save data to.DataDirectory = "data")@@ -20,4 +18,6 @@ const (var (// PublicHLSStoragePath is the directory we write public HLS files to for distribution.PublicHLSStoragePath = filepath.Join(WebRoot, "hls")+ // BackupDirectory is the directory we write backup files to.+ BackupDirectory = filepath.Join(DataDirectory, "backup"))diff --git a/core/data/data.go b/core/data/data.goindex 74321dbd28..b2484c30c9 100644--- a/core/data/data.go+++ b/core/data/data.go@@ -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:diff --git a/main.go b/main.goindex 1568be5e94..40078bd1c4 100644--- a/main.go+++ b/main.go@@ -35,6 +35,7 @@ func main() {dbFile := flag.String("database", "", "Path to the database file.")logDirectory := flag.String("logdir", "", "Directory where logs will be written to")+ backupDirectory := flag.String("backupdir", "", "Directory where backups will be written to")enableDebugOptions := flag.Bool("enableDebugFeatures", false, "Enable additional debugging options.")enableVerboseLogging := flag.Bool("enableVerboseLogging", false, "Enable additional logging.")restoreDatabaseFile := flag.String("restoreDatabase", "", "Restore an Owncast database backup")@@ -62,6 +63,10 @@ func main() {configureLogging(*enableDebugOptions, *enableVerboseLogging)log.Infoln(config.GetReleaseString())+ if *backupDirectory != "" {+ config.BackupDirectory = *backupDirectory+ }+// Create the data directory if neededif !utils.DoesFileExists("data") {os.Mkdir("./data", 0700)diff --git a/utils/backup.go b/utils/backup.goindex b030e3952e..19edde1ae1 100644--- a/utils/backup.go+++ b/utils/backup.go@@ -10,6 +10,7 @@ import ("io""io/ioutil""os"+ "path/filepath"_ "github.com/mattn/go-sqlite3""github.com/schollz/sqlite3dump"@@ -59,6 +60,15 @@ func Restore(backupFile string, databaseFile string) error {func Backup(db *sql.DB, backupFile string) {log.Traceln("Backing up database to", backupFile)+ BackupDirectory := filepath.Dir(backupFile)++ if !DoesFileExists(BackupDirectory) {+ err := os.MkdirAll(BackupDirectory, 0700)+ if err != nil {+ log.Fatalln(err)+ }+ }+// Dump the entire database as plain text sqlvar b bytes.Bufferout := bufio.NewWriter(&b)