read / write state
This commit is contained in:
parent
678b75ae6f
commit
56bc215f26
2 changed files with 35 additions and 1 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -111,3 +111,4 @@ venv.bak/
|
|||
.lsp/
|
||||
.calva/
|
||||
.cpcache/
|
||||
infrastructure/backup/image/resources/backup-repository-state.edn
|
||||
|
|
33
infrastructure/backup/image/resources/restic_management.clj
Executable file
33
infrastructure/backup/image/resources/restic_management.clj
Executable file
|
@ -0,0 +1,33 @@
|
|||
#! /usr/bin/env bb
|
||||
|
||||
(ns restic-management
|
||||
(:require
|
||||
[clojure.spec.alpha :as s]
|
||||
[clojure.java.io :as io]
|
||||
[clojure.edn :as edn]))
|
||||
|
||||
(s/def ::state string?)
|
||||
|
||||
(s/def ::backup-repository-state
|
||||
(s/keys :req-un [::state]))
|
||||
|
||||
(def state {:state ""})
|
||||
|
||||
(defn store-backup-repository-state [s]
|
||||
(spit "backup-repository-state.edn" s))
|
||||
|
||||
(defn read-backup-repository-state []
|
||||
(try
|
||||
(with-open [r (io/reader "backup-repository-state.edn")]
|
||||
(edn/read (java.io.PushbackReader. r)))
|
||||
|
||||
(catch java.io.IOException e
|
||||
(printf "Couldn't open '%s': %s\n" "backup-repository-state.edn" (.getMessage e)))
|
||||
(catch RuntimeException e
|
||||
(printf "Error parsing edn file '%s': %s\n" "backup-repository-state.edn" (.getMessage e)))))
|
||||
|
||||
(println (read-backup-repository-state))
|
||||
|
||||
(println (:state (read-backup-repository-state)))
|
||||
|
||||
(println (s/valid? ::backup-repository-state (read-backup-repository-state)))
|
Loading…
Reference in a new issue