summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkaa <kaa@disroot.org>2024-11-16 15:33:31 -0800
committerkaa <kaa@disroot.org>2024-11-16 15:33:31 -0800
commit0806d76f4530669569f2be8030795fd69eced035 (patch)
tree310dddc703a821f72a59e8e995ac6391d83fcfcb
Janky beginning.
-rw-r--r--dump157
-rw-r--r--restore.go75
-rwxr-xr-xrestore.sh4
3 files changed, 236 insertions, 0 deletions
diff --git a/dump b/dump
new file mode 100644
index 0000000..7abe61e
--- /dev/null
+++ b/dump
@@ -0,0 +1,157 @@
+ID Time Host Tags Paths
+---------------------------------------------------------------------------------------------
+85b2107d 2024-06-08 02:32:54 devuan /mnt/audio
+
+d096e88c 2024-06-08 02:51:44 devuan /mnt/auth
+
+24f4655e 2024-06-08 02:52:45 devuan /mnt/Mesa
+
+ed6861a3 2024-06-08 03:51:45 laptosh.my.domain /bank/audio
+
+41bcebac 2024-06-08 03:54:19 laptosh.my.domain /bank/high
+
+dc48b9b2 2024-06-09 16:18:25 laptosh.my.domain /bank/font
+
+85950922 2024-06-09 21:33:06 laptosh.my.domain /bank/auth
+ /bank/backups
+ /bank/book
+ /bank/club
+ /bank/config
+ /bank/doc
+ /bank/draw
+ /bank/etc
+ /bank/fmt
+ /bank/form
+ /bank/g
+ /bank/grub
+ /bank/junk
+ /bank/mail
+ /bank/meme
+ /bank/midi
+ /bank/misc
+ /bank/music
+ /bank/notes
+ /bank/omid
+ /bank/pal
+ /bank/paper
+ /bank/pic
+ /bank/poet
+ /bank/rom
+ /bank/router
+ /bank/sh
+ /bank/shot
+ /bank/site
+ /bank/src
+ /bank/vector
+ /bank/vid
+ /bank/vpn
+ /bank/web
+ /bank/whisper
+ /bank/y
+ /bank/zy
+
+72a2972a 2024-06-16 20:51:04 laptosh.my.domain /bank/auth
+ /bank/boot
+ /bank/config
+ /bank/doc
+ /bank/font
+ /bank/g
+ /bank/junk
+ /bank/make
+ /bank/midi
+ /bank/music
+ /bank/router
+ /bank/servers
+ /bank/sf2
+ /bank/sh
+ /bank/shot
+ /bank/site
+ /bank/vid
+
+4613953f 2024-06-17 06:20:22 laptosh.my.domain /bank/audio
+
+bcc0dbb1 2024-06-23 17:11:42 laptosh.my.domain /bank/audio
+ /bank/auth
+ /bank/config
+ /bank/doc
+ /bank/draw
+ /bank/fmt
+ /bank/font/site
+ /bank/form
+ /bank/g
+ /bank/junk
+ /bank/make
+ /bank/midi
+ /bank/pic/oldsdcard
+ /bank/shot
+ /bank/vid
+
+54bd4d23 2024-06-30 20:55:00 laptosh.my.domain /bank/audio
+ /bank/auth
+ /bank/config
+ /bank/doc
+ /bank/junk
+ /bank/make
+ /bank/midi
+ /bank/pic
+ /bank/servers
+ /bank/shot
+ /bank/vid
+
+a6abb6f2 2024-06-30 21:42:18 laptosh.my.domain /bank/font/site
+
+9441a4b0 2024-07-22 04:12:22 laptosh.my.domain /bank/auth
+ /bank/fmt
+ /bank/font/site
+ /bank/mart
+ /bank/pic
+ /bank/sh
+ /bank/shot
+ /bank/src/HamsterHelper.user.js
+ /bank/src/b.c
+ /bank/src/booksift
+ /bank/src/canup
+ /bank/src/cnt.c
+ /bank/src/h
+ /bank/src/har
+ /bank/src/l.c
+ /bank/src/lenlim.c
+ /bank/src/ll.c
+ /bank/src/neocities
+ /bank/src/off
+ /bank/src/q.c
+ /bank/src/ref
+ /bank/src/sample.c
+ /bank/src/sdlpng.c
+ /bank/src/test_glfw.c
+ /bank/src/winls.c
+ /bank/src/xor.c
+
+a8e43b98 2024-08-09 01:16:25 laptosh.my.domain /bank/auth
+ /bank/book
+ /bank/font/site
+ /bank/form
+ /bank/rfc
+ /bank/sh
+
+fe612de3 2024-08-18 02:11:17 laptosh.my.domain /bank/auth
+ /bank/book
+ /bank/fmt
+ /bank/font
+ /bank/form
+ /bank/pic
+ /bank/shot
+
+c8bf848f 2024-08-24 17:01:39 laptosh.my.domain /bank/vid/greg
+
+05ac34b2 2024-08-25 09:35:45 laptosh.my.domain /bank/vid
+ /bank/vid/greg
+
+37e2ace6 2024-09-08 15:00:03 laptosh.my.domain /bank/font/site
+ /bank/sh
+ /bank/src
+ /bank/vid
+
+ac4eb291 2024-09-11 20:29:10 laptosh.my.domain /bank/club/old
+---------------------------------------------------------------------------------------------
+19 snapshots
diff --git a/restore.go b/restore.go
new file mode 100644
index 0000000..f99196a
--- /dev/null
+++ b/restore.go
@@ -0,0 +1,75 @@
+/* Restore from a series of restic snapshots. */
+package main
+
+import (
+ "fmt"
+ "os"
+ "io"
+ "log"
+ "strings"
+ "slices"
+)
+
+type Snapshot struct {
+ id string
+ dirs []string
+}
+
+func main() {
+ body, err := io.ReadAll(os.Stdin)
+ if err != nil {
+ log.Fatal(err)
+ }
+
+ var shots []Snapshot
+ var current Snapshot
+
+ lines := strings.Split(string(body), "\n")
+ for _, s := range lines[2:len(lines) - 3] {
+ split := strings.Split(s, " ")
+ if len(s) == 0 {
+ shots = append(shots, current)
+ // Old snapshot is garbage collected.
+ current = Snapshot{}
+ } else if s[0] == ' ' {
+ // Directory at the end of line.
+ current.dirs = append(current.dirs, split[len(split) - 1])
+ } else {
+ // New snapshot.
+ current.id = split[0]
+ current.dirs = []string{split[len(split) - 1]}
+ }
+ }
+
+ // Last not followed by blank line.
+ shots = append(shots, current)
+
+ /*
+ for _, shot := range shots {
+ fmt.Println(shot.id)
+ for _, dir := range shot.dirs {
+ fmt.Println("\t" + dir)
+ }
+ } */
+
+ /* Traverse through the snapshots in reverse order.
+ The earlier entries covered by current are removed. */
+ seen := []string{}
+ list := make(map[string]string)
+ for i := len(shots) - 1; i >= 0; i-- {
+ for _, dir := range(shots[i].dirs) {
+ if !slices.Contains(seen, dir) {
+ seen = append(seen, dir)
+ list[shots[i].id] += dir + ","
+ }
+ }
+ }
+
+ for id, paths := range list {
+ for _, dir := range strings.Split(paths, ",") {
+ if dir != "" {
+ fmt.Println("restic restore " + id + ":" + dir + " --overwrite=if-newer --target=" + dir)
+ }
+ }
+ }
+}
diff --git a/restore.sh b/restore.sh
new file mode 100755
index 0000000..316b3ec
--- /dev/null
+++ b/restore.sh
@@ -0,0 +1,4 @@
+#!/bin/sh
+
+go run restore.go < dump | sed -e 's|$|;|' -e 's|:/[^/]*/|:/|' | grep -v '\.'
+#go run restore.go < dump | grep bank | sed -e "s|$| --target /bank|" -e "s|/bank||" -e 's|$|;|' | grep -v '\.'