create backup
parent
865c7b9789
commit
77783a3405
|
@ -3,8 +3,11 @@ package app
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
"os/exec"
|
||||||
"os/user"
|
"os/user"
|
||||||
|
"path"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
"time"
|
||||||
|
|
||||||
"git.sr.ht/~rockorager/vaxis"
|
"git.sr.ht/~rockorager/vaxis"
|
||||||
"git.tilde.town/nbsp/neofeels/ttbp"
|
"git.tilde.town/nbsp/neofeels/ttbp"
|
||||||
|
@ -57,6 +60,10 @@ func (management *Management) Event(state *ui.State, event vaxis.Event) (process
|
||||||
case 0:
|
case 0:
|
||||||
user, _ := user.Current()
|
user, _ := user.Current()
|
||||||
ui.ViewChange <- NewUserPage(user.Username, true)
|
ui.ViewChange <- NewUserPage(user.Username, true)
|
||||||
|
// case 1:
|
||||||
|
case 2:
|
||||||
|
management.SaveBackup(state)
|
||||||
|
// case 3:
|
||||||
case 4:
|
case 4:
|
||||||
ui.ViewChange <- NewBury()
|
ui.ViewChange <- NewBury()
|
||||||
case 5:
|
case 5:
|
||||||
|
@ -100,6 +107,44 @@ func wipeAccount() {
|
||||||
close(ui.Quit)
|
close(ui.Quit)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (management *Management) SaveBackup(state *ui.State) {
|
||||||
|
os.MkdirAll(ttbp.PathUserBackups, 0700)
|
||||||
|
filename := time.Now().Format("feels-backup-20060102-150405.tar.gz")
|
||||||
|
|
||||||
|
exec.Command("tar", "-C", ttbp.PathUserFeels, "-czf", filename, "entries").Run()
|
||||||
|
exec.Command("tar", "-C", ttbp.PathUserFeels, "-czf", path.Join(ttbp.PathUserBackups, filename), "entries").Run()
|
||||||
|
|
||||||
|
management.Draw(state)
|
||||||
|
win := state.Window()
|
||||||
|
win.New(win.Width/2-14, win.Height/2-2+management.list.Index(), 28, 1).Print(vaxis.Segment{
|
||||||
|
Text: " backup saved ",
|
||||||
|
Style: vaxis.Style{
|
||||||
|
Foreground: vaxis.IndexColor(2),
|
||||||
|
Attribute: vaxis.AttrReverse,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
state.Render()
|
||||||
|
loop:
|
||||||
|
for ev := range state.Events() {
|
||||||
|
switch ev.(type) {
|
||||||
|
case vaxis.Resize, vaxis.Redraw:
|
||||||
|
management.Draw(state)
|
||||||
|
win.New(win.Width/2-14, win.Height/2-2+management.list.Index(), 28, 1).Print(vaxis.Segment{
|
||||||
|
Text: " backup saved ",
|
||||||
|
Style: vaxis.Style{
|
||||||
|
Foreground: vaxis.IndexColor(2),
|
||||||
|
Attribute: vaxis.AttrReverse,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
state.Render()
|
||||||
|
case vaxis.Key:
|
||||||
|
if ev.(vaxis.Key).EventType == vaxis.EventPress {
|
||||||
|
break loop
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// TODO: abstract this to our own List type
|
// TODO: abstract this to our own List type
|
||||||
// TODO: figure out a less janky way instead of nesting event channels
|
// TODO: figure out a less janky way instead of nesting event channels
|
||||||
func (management *Management) Confirmation(state *ui.State, action func(), message string) {
|
func (management *Management) Confirmation(state *ui.State, action func(), message string) {
|
||||||
|
|
|
@ -30,6 +30,7 @@ var (
|
||||||
PathUserConfig = path.Join(PathUserFeels, "config")
|
PathUserConfig = path.Join(PathUserFeels, "config")
|
||||||
PathUserEntries = path.Join(PathUserFeels, "entries")
|
PathUserEntries = path.Join(PathUserFeels, "entries")
|
||||||
PathUserBuried = path.Join(PathUserFeels, "buried")
|
PathUserBuried = path.Join(PathUserFeels, "buried")
|
||||||
|
PathUserBackups = path.Join(PathUserFeels, "backups")
|
||||||
PathUserWWW = path.Join(PathUserFeels, "www")
|
PathUserWWW = path.Join(PathUserFeels, "www")
|
||||||
PathUserRc = path.Join(PathUserConfig, "ttbprc")
|
PathUserRc = path.Join(PathUserConfig, "ttbprc")
|
||||||
PathUserNopub = path.Join(PathUserConfig, "nopub")
|
PathUserNopub = path.Join(PathUserConfig, "nopub")
|
||||||
|
|
Loading…
Reference in New Issue