From 174184feb209f687f183e2d951c10227069bf064 Mon Sep 17 00:00:00 2001
From: toshski <104477758+toshski@users.noreply.github.com>
Date: Sat, 25 Nov 2023 05:26:00 +1300
Subject: [PATCH] feat: Add XBVR config settings to Backup/Restore (#1508)
---
pkg/api/tasks.go | 3 ++-
pkg/migrations/migrations.go | 2 +-
pkg/tasks/content.go | 22 ++++++++++++++++++-
.../sections/OptionsSceneDataImportExport.vue | 13 +++++++++--
4 files changed, 35 insertions(+), 5 deletions(-)
diff --git a/pkg/api/tasks.go b/pkg/api/tasks.go
index 7d5a439c0..f1a090994 100644
--- a/pkg/api/tasks.go
+++ b/pkg/api/tasks.go
@@ -172,10 +172,11 @@ func (i TaskResource) backupBundle(req *restful.Request, resp *restful.Response)
inclExtRefs, _ := strconv.ParseBool(req.QueryParameter("inclExtRefs"))
inclActors, _ := strconv.ParseBool(req.QueryParameter("inclActors"))
inclActorActions, _ := strconv.ParseBool(req.QueryParameter("inclActorActions"))
+ inclConfig, _ := strconv.ParseBool(req.QueryParameter("inclConfig"))
playlistId := req.QueryParameter("playlistId")
download := req.QueryParameter("download")
- bundle := tasks.BackupBundle(inclAllSites, onlyIncludeOfficalSites, inclScenes, inclFileLinks, inclCuepoints, inclHistory, inclPlaylists, inclActorAkas, inclTagGroups, inclVolumes, inclSites, inclActions, inclExtRefs, inclActors, inclActorActions, playlistId, "", "")
+ bundle := tasks.BackupBundle(inclAllSites, onlyIncludeOfficalSites, inclScenes, inclFileLinks, inclCuepoints, inclHistory, inclPlaylists, inclActorAkas, inclTagGroups, inclVolumes, inclSites, inclActions, inclExtRefs, inclActors, inclActorActions, inclConfig, playlistId, "", "")
if download == "true" {
resp.WriteHeaderAndEntity(http.StatusOK, ResponseBackupBundle{Response: "Ready to Download from http://xxx.xxx.xxx.xxx:9999/download/xbvr-content-bundle.json"})
} else {
diff --git a/pkg/migrations/migrations.go b/pkg/migrations/migrations.go
index afa05ed4c..13c0647de 100644
--- a/pkg/migrations/migrations.go
+++ b/pkg/migrations/migrations.go
@@ -1483,7 +1483,7 @@ func Migrate() {
}
// backup bundle
common.Log.Infof("Creating pre-migration backup, please waiit, backups can take some time on a system with a large number of scenes ")
- tasks.BackupBundle(true, false, true, true, true, true, true, true, true, true, true, true, true, true, true, "0", "xbvr-premigration-bundle.json", "2")
+ tasks.BackupBundle(true, false, true, true, true, true, true, true, true, true, true, true, true, true, true, false, "0", "xbvr-premigration-bundle.json", "2")
common.Log.Infof("Go to download/xbvr-premigration-bundle.json, or http://xxx.xxx.xxx.xxx:9999/download/xbvr-premigration-bundle.json if you need access to the backup")
var sites []models.Site
officalSiteChanges := []SiteChange{
diff --git a/pkg/tasks/content.go b/pkg/tasks/content.go
index 7c0dc3df1..08495e36f 100644
--- a/pkg/tasks/content.go
+++ b/pkg/tasks/content.go
@@ -70,6 +70,7 @@ type BackupContentBundle struct {
ExternalRefs []models.ExternalReference `xbvrbackup:"externalReferences"`
Actors []models.Actor `xbvrbackup:"actors"`
ActionActors []BackupActionActor `xbvrbackup:"actionActors"`
+ Kvs []models.KV `xbvrbackup:"config"`
}
type RequestRestore struct {
InclAllSites bool `json:"allSites"`
@@ -89,6 +90,7 @@ type RequestRestore struct {
InclExternalRefs bool `json:"inclExtRefs"`
InclActors bool `json:"inclActors"`
InclActorActions bool `json:"inclActorActions"`
+ InclConfig bool `json:"inclConfig"`
}
func CleanTags() {
@@ -512,7 +514,7 @@ func ImportBundleV1(bundleData ContentBundle) {
}
-func BackupBundle(inclAllSites bool, onlyIncludeOfficalSites bool, inclScenes bool, inclFileLinks bool, inclCuepoints bool, inclHistory bool, inclPlaylists bool, InclActorAkas bool, inclTagGroups bool, inclVolumes bool, inclSites bool, inclActions bool, inclExtRefs bool, inclActors bool, inclActorActions bool, playlistId string, outputBundleFilename string, version string) string {
+func BackupBundle(inclAllSites bool, onlyIncludeOfficalSites bool, inclScenes bool, inclFileLinks bool, inclCuepoints bool, inclHistory bool, inclPlaylists bool, InclActorAkas bool, inclTagGroups bool, inclVolumes bool, inclSites bool, inclActions bool, inclExtRefs bool, inclActors bool, inclActorActions bool, inclConfig bool, playlistId string, outputBundleFilename string, version string) string {
var out BackupContentBundle
var content []byte
exportCnt := 0
@@ -699,6 +701,10 @@ func BackupBundle(inclAllSites bool, onlyIncludeOfficalSites bool, inclScenes bo
backupActionActorList = append(backupActionActorList, actorsActions)
}
}
+ var kvs []models.KV
+ if inclConfig {
+ db.Where("`key` not like 'lock%'").Find(&kvs)
+ }
var err error
out = BackupContentBundle{
@@ -717,6 +723,7 @@ func BackupBundle(inclAllSites bool, onlyIncludeOfficalSites bool, inclScenes bo
ExternalRefs: externalReferences,
Actors: actors,
ActionActors: backupActionActorList,
+ Kvs: kvs,
}
var json = jsoniter.Config{
@@ -836,6 +843,9 @@ func RestoreBundle(request RequestRestore) {
if request.InclActorActions {
RestoreActionActors(bundleData.ActionActors, request.Overwrite, db)
}
+ if request.InclConfig {
+ RestoreKvs(bundleData.Kvs, db)
+ }
if request.InclScenes {
CountTags()
@@ -1542,6 +1552,16 @@ func RestoreActionActors(actionActorsList []BackupActionActor, overwrite bool, d
}
tlog.Infof("%v Actors with edits restored", addedCnt)
}
+func RestoreKvs(kvs []models.KV, db *gorm.DB) {
+ tlog := log.WithField("task", "scrape")
+ tlog.Infof("Restoring System Config")
+
+ for _, kv := range kvs {
+ models.SaveWithRetry(db, &kv)
+ }
+
+ tlog.Infof("System Config Restored ")
+}
func CountTags() {
var tag models.Tag
diff --git a/ui/src/views/options/sections/OptionsSceneDataImportExport.vue b/ui/src/views/options/sections/OptionsSceneDataImportExport.vue
index d4a879f92..687a5f710 100644
--- a/ui/src/views/options/sections/OptionsSceneDataImportExport.vue
+++ b/ui/src/views/options/sections/OptionsSceneDataImportExport.vue
@@ -150,6 +150,13 @@