summaryrefslogtreecommitdiff
path: root/etc/backup.clj
diff options
context:
space:
mode:
Diffstat (limited to 'etc/backup.clj')
-rw-r--r--etc/backup.clj45
1 files changed, 45 insertions, 0 deletions
diff --git a/etc/backup.clj b/etc/backup.clj
new file mode 100644
index 0000000..ae4a380
--- /dev/null
+++ b/etc/backup.clj
@@ -0,0 +1,45 @@
+(ns backup
+ (:require [clojure.edn :as edn]
+ [datomic.require :as req]
+ [datomic.cli :as cli]))
+
+(def commands
+ "Map of command names to descriptions of command arguments."
+ {"backup"
+ {:f 'datomic.backup-cli/backup
+ :named #{{:long-name :from-db-uri :required true :doc "URI for backup source"}
+ {:long-name :to-backup-uri :required true :doc "URI for backup destination"}}
+ :positional [:from-db-uri :to-backup-uri]}
+ "list"
+ {:f 'datomic.backup-cli/list-backups
+ :named #{{:long-name :backup-uri :required true :doc "backup URI"}}
+ :positional [:backup-uri :to-db-uri]}
+ "verify"
+ {:f 'datomic.backup-cli/verify-backup
+ :named #{{:long-name :backup-uri :required true :doc "URI of backup"}
+ {:long-name :read-all :required true :doc "Verify that every segment is readable" :coerce #(boolean (edn/read-string %))}
+ {:long-name :t :required true :doc "Point in time (t) to verify" :coerce #(Long. %)}}
+ :positional [:backup-uri :read-all :t]}
+ "restore"
+ {:f 'datomic.backup-cli/restore
+ :named #{{:long-name :from-backup-uri :required true :doc "URI for restore source"}
+ {:long-name :to-db-uri :required true :doc "URI for restore destination"}
+ {:long-name :t :doc "Point in time (t) to restore, defaults to most recent"
+ :default nil :coerce #(Long. %)}}
+ :positional [:from-backup-uri :to-db-uri :t]}})
+
+(defn -main
+ [& [command & cli-args]]
+ (if-let [{:keys [f named positional vararg]} (get commands command)]
+ (let [args (cli/parse-or-exit! command cli-args named positional vararg)]
+ (try
+ (when-let [result (req/require-and-run f args)]
+ (println result))
+ (catch Throwable t
+ (.printStackTrace t)
+ (cli/fail (.getMessage t))))
+ (when @cli/exit-after-command
+ (System/exit (if @cli/failed 1 0))))
+ (binding [*out* *err*]
+ (println (str "Bad command: \"" command "\"."))
+ (System/exit 2))))