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"
|
||||
"fmt"
|
||||
"html/template"
|
||||
"io"
|
||||
"io/fs"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
|
@ -972,7 +973,70 @@ func (web *Web) createBackup(backupPath string) error {
|
|||
|
||||
// backupTest (/backup/test) tests the selected backup file
|
||||
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
|
||||
|
|
|
@ -4,40 +4,66 @@ GoWatch Backups
|
|||
{{define "content"}}
|
||||
|
||||
<div class="container row">
|
||||
<div class="row h3 justify-content-center">
|
||||
Backups
|
||||
<div class="row h3 justify-content-center {{ if .Error }} text-danger {{ else }} text-success {{ end }}">
|
||||
Backup Test: {{ .BackupPath }}
|
||||
</div>
|
||||
{{ if .Error }}
|
||||
<div class="row h3 justify-content-center text-danger">
|
||||
<div class="row h3 justify-content-center">
|
||||
{{ .Error }}
|
||||
</div>
|
||||
{{ end }}
|
||||
<table class="table table-striped table-hover">
|
||||
<table class="table table-striped table-hover caption-top">
|
||||
<caption class="h3">Watches</caption>
|
||||
<thead>
|
||||
<tr class="table-dark">
|
||||
<th>File</th>
|
||||
<th>Test</th>
|
||||
<th>Restore</th>
|
||||
<th>ID</th>
|
||||
<th>Name</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{{ range $i, $backup := .Backups }}
|
||||
{{ range $watch := .Backup.Watches }}
|
||||
<tr>
|
||||
<td class="h5">{{ $backup }}</td>
|
||||
<td>
|
||||
<a class="btn btn-success">
|
||||
Test
|
||||
</a>
|
||||
</td>
|
||||
<td>
|
||||
<a class="btn btn-danger">
|
||||
Restore
|
||||
</a>
|
||||
</td>
|
||||
<td class="h5">{{ $watch.ID }}</td>
|
||||
<td class="h5">{{ $watch.Name }}</td>
|
||||
</tr>
|
||||
{{ end }}
|
||||
</tbody>
|
||||
</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>
|
||||
|
||||
{{end}}
|
|
@ -26,7 +26,7 @@ GoWatch Backups
|
|||
<tr>
|
||||
<td class="h5">{{ $backup }}</td>
|
||||
<td>
|
||||
<a class="btn btn-success">
|
||||
<a href="/backup/test/{{ $i }}" class="btn btn-success">
|
||||
Test
|
||||
</a>
|
||||
</td>
|
||||
|
|
2
todo.md
2
todo.md
|
@ -6,7 +6,7 @@
|
|||
- edit.ts
|
||||
- diagram.ts
|
||||
- ~~scheduled backup~~
|
||||
- test
|
||||
- ~~test~~
|
||||
- restore
|
||||
- delete
|
||||
- download
|
||||
|
|
Loading…
Add table
Reference in a new issue