feat: add full snapshot downloads and safe manual restore
This commit is contained in:
+17
-1
@@ -23,6 +23,14 @@ var backupIDPattern = regexp.MustCompile("^[a-f0-9]{32}$")
|
||||
var configBodySlots = make(chan struct{}, 4)
|
||||
|
||||
func (a *API) config(w http.ResponseWriter, r *http.Request, i store.Instance, action string) {
|
||||
if action == "snapshots" && r.Method == http.MethodGet && r.URL.Query().Get("download") != "" {
|
||||
a.snapshotDownload(w, r, i)
|
||||
return
|
||||
}
|
||||
if action == "snapshots" && r.Method == http.MethodPost {
|
||||
a.snapshotRestore(w, r, i)
|
||||
return
|
||||
}
|
||||
if action == "snapshots" || (action == "backups" && r.Method == http.MethodDelete) {
|
||||
a.backupManagement(w, r, i, action)
|
||||
return
|
||||
@@ -472,6 +480,15 @@ func (a *API) config(w http.ResponseWriter, r *http.Request, i store.Instance, a
|
||||
return
|
||||
}
|
||||
snapshot := "pre-restore-" + store.ID()
|
||||
failed := "failed-restore-" + store.ID()
|
||||
if e = a.recordSnapshot(i, snapshot, i.Version, i.ImageID); e != nil {
|
||||
fail(w, 500, "snapshot metadata unavailable")
|
||||
return
|
||||
}
|
||||
if e = a.recordSnapshot(i, failed, i.Version, i.ImageID); e != nil {
|
||||
fail(w, 500, "snapshot metadata unavailable")
|
||||
return
|
||||
}
|
||||
if _, e = a.quotaSnapshot(i.UID, parent, restoredBytes); e != nil {
|
||||
fail(w, 413, "quota exceeded or snapshot size unavailable")
|
||||
return
|
||||
@@ -540,7 +557,6 @@ func (a *API) config(w http.ResponseWriter, r *http.Request, i store.Instance, a
|
||||
fail(w, 500, "restore rollback requires runtime stop")
|
||||
return
|
||||
}
|
||||
failed := "failed-restore-" + store.ID()
|
||||
if parent.Rename("home", failed) != nil || parent.Rename(snapshot, "home") != nil || upgradeSync(parent) != nil {
|
||||
a.s.SetInstance(i.ID, "error")
|
||||
fail(w, 500, "restore rollback requires administrator recovery")
|
||||
|
||||
Reference in New Issue
Block a user