2024-11-29 14:14:01 +00:00
|
|
|
#!/usr/bin/env bb
|
|
|
|
|
|
|
|
(require '[babashka.tasks :as tasks]
|
|
|
|
'[dda.backup.restic :as rc]
|
2024-12-11 18:48:23 +00:00
|
|
|
'[dda.backup.backup :as bak]
|
|
|
|
'[dda.backup.restore :as rs])
|
2024-11-29 14:14:01 +00:00
|
|
|
|
2024-12-24 14:50:17 +00:00
|
|
|
(def restic-repo {:password-file "/restic-pwd"
|
|
|
|
:new-password-file "/new-restic-pwd"
|
|
|
|
:restic-repository "/restic-repo"
|
|
|
|
:debug true})
|
2024-11-29 14:14:01 +00:00
|
|
|
|
|
|
|
(def file-config (merge restic-repo {:backup-path "files"
|
2024-12-28 17:30:14 +00:00
|
|
|
:execution-directory "/var/backups/"
|
|
|
|
:files ["test-backup"]
|
|
|
|
:restore-target-directory "test-restore"}))
|
2024-11-29 14:14:01 +00:00
|
|
|
|
|
|
|
(def dry-run {:dry-run true :debug true})
|
|
|
|
|
|
|
|
(defn prepare!
|
|
|
|
[]
|
2024-12-11 18:48:23 +00:00
|
|
|
(spit "/tmp/file_password" "file-password")
|
|
|
|
|
2024-12-24 14:50:17 +00:00
|
|
|
(spit "/restic-pwd" "oldPassword")
|
|
|
|
(spit "/new-restic-pwd" "newPassword")
|
2024-12-11 18:48:23 +00:00
|
|
|
|
2024-12-28 17:30:14 +00:00
|
|
|
(tasks/shell "mkdir" "-p" "/var/backups/test-backup")
|
|
|
|
(spit "/var/backups/test-backup/file" "I was here")
|
|
|
|
(tasks/shell "mkdir" "-p" "/var/backups/test-restore"))
|
2024-11-29 14:14:01 +00:00
|
|
|
|
|
|
|
(defn restic-repo-init!
|
|
|
|
[]
|
2024-12-11 18:48:23 +00:00
|
|
|
(println "restic-repo-init!")
|
2024-12-24 14:50:17 +00:00
|
|
|
(rc/init! file-config))
|
2024-12-11 18:48:23 +00:00
|
|
|
|
|
|
|
(defn restic-backup!
|
|
|
|
[]
|
|
|
|
(println "restic-backup!")
|
2024-12-24 14:50:17 +00:00
|
|
|
(bak/backup-file! file-config))
|
2024-12-11 18:48:23 +00:00
|
|
|
|
|
|
|
(defn list-snapshots!
|
|
|
|
[]
|
|
|
|
(println "list-snapshots!")
|
2024-12-24 14:50:17 +00:00
|
|
|
(rc/list-snapshots! file-config))
|
2024-12-11 18:48:23 +00:00
|
|
|
|
|
|
|
|
|
|
|
(defn restic-restore!
|
|
|
|
[]
|
|
|
|
(println "restic-restore!")
|
2024-12-24 14:50:17 +00:00
|
|
|
(rs/restore-file! file-config))
|
2024-12-11 18:48:23 +00:00
|
|
|
|
|
|
|
(defn change-password!
|
|
|
|
[]
|
|
|
|
(println "change-password!")
|
2024-12-24 14:50:17 +00:00
|
|
|
(rc/change-password! file-config))
|
2024-12-11 18:48:23 +00:00
|
|
|
|
2024-11-29 14:14:01 +00:00
|
|
|
|
|
|
|
(prepare!)
|
|
|
|
(restic-repo-init!)
|
2024-12-11 18:48:23 +00:00
|
|
|
(restic-backup!)
|
|
|
|
(list-snapshots!)
|
|
|
|
(restic-restore!)
|
|
|
|
(change-password!)
|