added testing of backup files
This commit is contained in:
parent
32243fb39e
commit
17f29cb175
4 changed files with 111 additions and 21 deletions
64
main.go
64
main.go
|
@ -9,6 +9,7 @@ import (
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"html/template"
|
"html/template"
|
||||||
|
"io"
|
||||||
"io/fs"
|
"io/fs"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"log"
|
"log"
|
||||||
|
@ -972,7 +973,70 @@ func (web *Web) createBackup(backupPath string) error {
|
||||||
|
|
||||||
// backupTest (/backup/test) tests the selected backup file
|
// backupTest (/backup/test) tests the selected backup file
|
||||||
func (web *Web) backupTest(c *gin.Context) {
|
func (web *Web) backupTest(c *gin.Context) {
|
||||||
|
importID, err := strconv.Atoi(c.Param("id"))
|
||||||
|
if err != nil {
|
||||||
|
c.AbortWithError(http.StatusBadRequest, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if importID < 0 {
|
||||||
|
c.Redirect(http.StatusSeeOther, "/backup/view")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if !viper.IsSet("database.backup") {
|
||||||
|
c.HTML(http.StatusOK, "backupTest", gin.H{"Error": "database.backup not set"})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if !viper.IsSet("database.backup.schedule") {
|
||||||
|
c.HTML(http.StatusOK, "backupTest", gin.H{"Error": "database.backup.schedule not set"})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if !viper.IsSet("database.backup.path") {
|
||||||
|
c.HTML(http.StatusOK, "backupTest", gin.H{"Error": "database.backup.path not set"})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
backupPath := viper.GetString("database.backup.path")
|
||||||
|
|
||||||
|
backupDir, err := filepath.Abs(filepath.Dir(backupPath))
|
||||||
|
if err != nil {
|
||||||
|
c.HTML(http.StatusOK, "backupTest", gin.H{"Error": err})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
filesInBackupDir, err := ioutil.ReadDir(backupDir)
|
||||||
|
if err != nil {
|
||||||
|
c.HTML(http.StatusOK, "backupTest", gin.H{"Error": err})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if importID >= len(filesInBackupDir) {
|
||||||
|
c.Redirect(http.StatusSeeOther, "/backup/view")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
backupFileName := filesInBackupDir[importID]
|
||||||
|
backupFullPath := filepath.Join(backupDir, backupFileName.Name())
|
||||||
|
backupFile, err := os.Open(backupFullPath)
|
||||||
|
if err != nil {
|
||||||
|
c.HTML(http.StatusOK, "backupTest", gin.H{"Error": err})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
defer backupFile.Close()
|
||||||
|
|
||||||
|
backupReader, err := gzip.NewReader(backupFile)
|
||||||
|
if err != nil {
|
||||||
|
c.HTML(http.StatusOK, "backupTest", gin.H{"Error": err})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
defer backupReader.Close()
|
||||||
|
rawBytes, err := io.ReadAll(backupReader)
|
||||||
|
|
||||||
|
var backup Backup
|
||||||
|
json.Unmarshal(rawBytes, &backup)
|
||||||
|
|
||||||
|
c.HTML(http.StatusOK, "backupTest", gin.H{
|
||||||
|
"Backup": backup,
|
||||||
|
"BackupPath": backupFullPath,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// exportWatch (/watch/export/:id) creates a json export of the current watch
|
// exportWatch (/watch/export/:id) creates a json export of the current watch
|
||||||
|
|
|
@ -4,40 +4,66 @@ GoWatch Backups
|
||||||
{{define "content"}}
|
{{define "content"}}
|
||||||
|
|
||||||
<div class="container row">
|
<div class="container row">
|
||||||
<div class="row h3 justify-content-center">
|
<div class="row h3 justify-content-center {{ if .Error }} text-danger {{ else }} text-success {{ end }}">
|
||||||
Backups
|
Backup Test: {{ .BackupPath }}
|
||||||
</div>
|
</div>
|
||||||
{{ if .Error }}
|
{{ if .Error }}
|
||||||
<div class="row h3 justify-content-center text-danger">
|
<div class="row h3 justify-content-center">
|
||||||
{{ .Error }}
|
{{ .Error }}
|
||||||
</div>
|
</div>
|
||||||
{{ end }}
|
{{ end }}
|
||||||
<table class="table table-striped table-hover">
|
<table class="table table-striped table-hover caption-top">
|
||||||
|
<caption class="h3">Watches</caption>
|
||||||
<thead>
|
<thead>
|
||||||
<tr class="table-dark">
|
<tr class="table-dark">
|
||||||
<th>File</th>
|
<th>ID</th>
|
||||||
<th>Test</th>
|
<th>Name</th>
|
||||||
<th>Restore</th>
|
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
{{ range $i, $backup := .Backups }}
|
{{ range $watch := .Backup.Watches }}
|
||||||
<tr>
|
<tr>
|
||||||
<td class="h5">{{ $backup }}</td>
|
<td class="h5">{{ $watch.ID }}</td>
|
||||||
<td>
|
<td class="h5">{{ $watch.Name }}</td>
|
||||||
<a class="btn btn-success">
|
|
||||||
Test
|
|
||||||
</a>
|
|
||||||
</td>
|
|
||||||
<td>
|
|
||||||
<a class="btn btn-danger">
|
|
||||||
Restore
|
|
||||||
</a>
|
|
||||||
</td>
|
|
||||||
</tr>
|
</tr>
|
||||||
{{ end }}
|
{{ end }}
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
|
<div class="row h4 justify-content-center">
|
||||||
|
Stored Values: {{ len .Backup.Values }}
|
||||||
|
</div>
|
||||||
|
<table class="table table-striped table-hover caption-top">
|
||||||
|
<caption class="h3">Filters</caption>
|
||||||
|
<thead>
|
||||||
|
<tr class="table-dark">
|
||||||
|
<th>ID</th>
|
||||||
|
<th>WatchID</th>
|
||||||
|
<th>Name</th>
|
||||||
|
<th>Type</th>
|
||||||
|
<th>Var1</th>
|
||||||
|
<th>Var2</th>
|
||||||
|
<th>Var3</th>
|
||||||
|
<th>X/Y</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
{{ range $filter := .Backup.Filters }}
|
||||||
|
<tr>
|
||||||
|
<td class="h5">{{ $filter.ID }}</td>
|
||||||
|
<td class="h5">{{ $filter.WatchID }}</td>
|
||||||
|
<td class="h5">{{ $filter.Name }}</td>
|
||||||
|
<td class="h5">{{ $filter.Type }}</td>
|
||||||
|
<td class="h5">{{ $filter.Var1 }}</td>
|
||||||
|
<td class="h5">{{ $filter.Var2 }}</td>
|
||||||
|
<td class="h5">{{ $filter.Var3 }}</td>
|
||||||
|
<td class="h5">{{ $filter.X }}/{{ $filter.Y }}</td>
|
||||||
|
</tr>
|
||||||
|
{{ end }}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
<div class="row h4 justify-content-center">
|
||||||
|
FilterConnections: {{ len .Backup.Connections }}
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{{end}}
|
{{end}}
|
|
@ -26,7 +26,7 @@ GoWatch Backups
|
||||||
<tr>
|
<tr>
|
||||||
<td class="h5">{{ $backup }}</td>
|
<td class="h5">{{ $backup }}</td>
|
||||||
<td>
|
<td>
|
||||||
<a class="btn btn-success">
|
<a href="/backup/test/{{ $i }}" class="btn btn-success">
|
||||||
Test
|
Test
|
||||||
</a>
|
</a>
|
||||||
</td>
|
</td>
|
||||||
|
|
2
todo.md
2
todo.md
|
@ -6,7 +6,7 @@
|
||||||
- edit.ts
|
- edit.ts
|
||||||
- diagram.ts
|
- diagram.ts
|
||||||
- ~~scheduled backup~~
|
- ~~scheduled backup~~
|
||||||
- test
|
- ~~test~~
|
||||||
- restore
|
- restore
|
||||||
- delete
|
- delete
|
||||||
- download
|
- download
|
||||||
|
|
Loading…
Add table
Reference in a new issue