Skip to content

Commit

Permalink
feat: Add XBVR config settings to Backup/Restore (#1508)
Browse files Browse the repository at this point in the history
  • Loading branch information
toshski authored Nov 24, 2023
1 parent 627fb83 commit 174184f
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 5 deletions.
3 changes: 2 additions & 1 deletion pkg/api/tasks.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion pkg/migrations/migrations.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
22 changes: 21 additions & 1 deletion pkg/tasks/content.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand All @@ -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() {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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{
Expand All @@ -717,6 +723,7 @@ func BackupBundle(inclAllSites bool, onlyIncludeOfficalSites bool, inclScenes bo
ExternalRefs: externalReferences,
Actors: actors,
ActionActors: backupActionActorList,
Kvs: kvs,
}

var json = jsoniter.Config{
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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
Expand Down
13 changes: 11 additions & 2 deletions ui/src/views/options/sections/OptionsSceneDataImportExport.vue
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,13 @@
<b-switch v-model="includeSites">Include Scraper Settings</b-switch>
</b-tooltip>
</b-field>
<b-field>
<b-tooltip
:label="isImport ? 'Requires restarting XBVR once complete. Include XBVR Configuration Settings. Preview setting, task schedules, etc.' : 'Includes passowrds/access tokens. Includes XBVR Configuration Settings. Preview settings, task schedules, etc.'"
size="is-large" :type="isImport ? 'is-warning is-light' : 'is-danger is-light'" multilined :delay="300" >
<b-switch v-model="includeConfig">Include Config Settings</b-switch>
</b-tooltip>
</b-field>
<b-button type="is-info is-small" style="margin-bottom: 1em;" @click="toggleSettingsIncludes()">Toggle Includes</b-button>
</div>
<hr />
Expand Down Expand Up @@ -219,6 +226,7 @@ export default {
includePlaylists: true,
includeVolumes: true,
includeSites: true,
includeConfig: false,
includeActorAkas: true,
includeExternalReferences: true,
includeTagGroups: true,
Expand Down Expand Up @@ -300,13 +308,13 @@ export default {
// put up a starting msg, as large files can cause it to appear to hang
this.$store.state.messages.lastScrapeMessage = 'Starting restore'
ky.post('/api/task/bundle/restore', {
json: { allSites: this.allSites == "true", onlyIncludeOfficalSites: this.onlyIncludeOfficalSites, inclScenes: this.includeScenes, inclHistory: this.includeHistory, inclLinks: this.includeFileLinks, inclCuepoints: this.includeCuepoints, inclActions: this.includeActions, inclPlaylists: this.includePlaylists, inclActorAkas: this.includeActorAkas, inclTagGroups: this.includeTagGroups, inclVolumes: this.includeVolumes, inclExtRefs: this.includeExternalReferences, inclSites: this.includeSites, inclActors: this.includeActors,inclActorActions: this.inclActorActions, overwrite: this.overwrite, uploadData: this.uploadData }
json: { allSites: this.allSites == "true", onlyIncludeOfficalSites: this.onlyIncludeOfficalSites, inclScenes: this.includeScenes, inclHistory: this.includeHistory, inclLinks: this.includeFileLinks, inclCuepoints: this.includeCuepoints, inclActions: this.includeActions, inclPlaylists: this.includePlaylists, inclActorAkas: this.includeActorAkas, inclTagGroups: this.includeTagGroups, inclVolumes: this.includeVolumes, inclExtRefs: this.includeExternalReferences, inclSites: this.includeSites, inclActors: this.includeActors,inclActorActions: this.inclActorActions, inclConfig: this.includeConfig, overwrite: this.overwrite, uploadData: this.uploadData }
})
this.file = null
}
},
backupContent () {
ky.get('/api/task/bundle/backup', { timeout: false, searchParams: { allSites: this.allSites == "true", onlyIncludeOfficalSites: this.onlyIncludeOfficalSites, inclScenes: this.includeScenes, inclHistory: this.includeHistory, inclLinks: this.includeFileLinks, inclCuepoints: this.includeCuepoints, inclActions: this.includeActions, inclPlaylists: this.includePlaylists, inclActorAkas: this.includeActorAkas, inclTagGroups: this.includeTagGroups, inclVolumes: this.includeVolumes, inclExtRefs: this.includeExternalReferences, inclSites: this.includeSites, inclActors: this.includeActors,inclActorActions: this.inclActorActions, playlistId: this.currentPlaylist, download: true } }).json().then(data => {
ky.get('/api/task/bundle/backup', { timeout: false, searchParams: { allSites: this.allSites == "true", onlyIncludeOfficalSites: this.onlyIncludeOfficalSites, inclScenes: this.includeScenes, inclHistory: this.includeHistory, inclLinks: this.includeFileLinks, inclCuepoints: this.includeCuepoints, inclActions: this.includeActions, inclPlaylists: this.includePlaylists, inclActorAkas: this.includeActorAkas, inclTagGroups: this.includeTagGroups, inclVolumes: this.includeVolumes, inclExtRefs: this.includeExternalReferences, inclSites: this.includeSites, inclActors: this.includeActors,inclActorActions: this.inclActorActions, inclConfig: this.includeConfig, playlistId: this.currentPlaylist, download: true } }).json().then(data => {
const link = document.createElement('a')
link.href = this.myUrl
link.click()
Expand All @@ -330,6 +338,7 @@ export default {
this.includePlaylists = !this.includePlaylists
this.includeVolumes=!this.includeVolumes
this.includeSites=!this.includeSites
this.includeConfig=!this.includeConfig
},
}
}
Expand Down

0 comments on commit 174184f

Please sign in to comment.