Compare commits
No commits in common. "1dac3406441320f3a2ba5ee5fd6b0bcf6800a7c5" and "2b2f2294ae8d4ce86563dc640e4b73fe10b887fb" have entirely different histories.
1dac340644
...
2b2f2294ae
6 changed files with 16 additions and 34 deletions
|
@ -2,6 +2,5 @@ FROM ubuntu:24.04
|
|||
|
||||
# install it
|
||||
ADD resources /tmp/
|
||||
RUN /tmp/install.sh
|
||||
ADD local/ /usr/local/lib/dda-backup
|
||||
RUN init-bb.bb
|
||||
RUN /tmp/install.sh
|
||||
|
|
|
@ -15,7 +15,7 @@ function babashka_install() {
|
|||
function main() {
|
||||
{
|
||||
upgradeSystem
|
||||
apt-get install -qqy ca-certificates curl gnupg postgresql-client-16 restic openjdk-21-jre-headless nano
|
||||
apt-get install -qqy ca-certificates curl gnupg postgresql-client-16 restic openjdk-21-jre-headless
|
||||
curl -Ss --fail https://www.postgresql.org/media/keys/ACCC4CF8.asc | gpg --dearmor | tee /etc/apt/trusted.gpg.d/postgresql-common_pgdg_archive_keyring.gpg
|
||||
sh -c 'echo "deb [signed-by=/etc/apt/trusted.gpg.d/postgresql-common_pgdg_archive_keyring.gpg] https://apt.postgresql.org/pub/repos/apt jammy-pgdg main" > /etc/apt/sources.list.d/pgdg.list'
|
||||
upgradeSystem
|
||||
|
@ -23,7 +23,8 @@ function main() {
|
|||
} > /dev/null
|
||||
|
||||
update-ca-certificates
|
||||
install -m 0700 -o root -g root /tmp/init-bb.bb /usr/local/bin/
|
||||
/tmp/init.bb
|
||||
|
||||
cleanupDocker
|
||||
}
|
||||
|
||||
|
|
|
@ -27,6 +27,4 @@
|
|||
(defn-spec drop-create-db! nil?
|
||||
[config ::pg-config]
|
||||
(let [config-w-defaults (merge default config)]
|
||||
(try (i/execute! (domain/db-drop-command config-w-defaults) config-w-defaults)
|
||||
(catch Exception e (println (.getMessage e))))
|
||||
(i/execute! (domain/db-create-command config-w-defaults) config-w-defaults)))
|
||||
(i/execute! (domain/db-drop-create-command config-w-defaults) config-w-defaults)))
|
||||
|
|
|
@ -68,17 +68,11 @@
|
|||
(defn-spec pgpass string?
|
||||
[config ::pg-config]
|
||||
(let [{:keys [pg-host pg-port pg-db pg-user pg-password]} config]
|
||||
(str pg-host ":" pg-port ":" pg-db ":" pg-user ":" pg-password "\n"
|
||||
pg-host ":" pg-port ":template1:" pg-user ":" pg-password "\n")))
|
||||
(str pg-host ":" pg-port ":" pg-db ":" pg-user ":" pg-password)))
|
||||
|
||||
(defn-spec db-drop-command ::cd/commands
|
||||
(defn-spec db-drop-create-command ::cd/commands
|
||||
[config ::pg-config]
|
||||
(let [{:keys [pg-db]} config
|
||||
config-w-template (merge config {:pg-db "template1"})]
|
||||
[(psql-command config-w-template ["-c" (str "DROP DATABASE \"" pg-db "\";")])]))
|
||||
|
||||
(defn-spec db-create-command ::cd/commands
|
||||
[config ::pg-config]
|
||||
(let [{:keys [pg-db]} config
|
||||
config-w-template (merge config {:pg-db "template1"})]
|
||||
[(psql-command config-w-template ["-c" (str "CREATE DATABASE \"" pg-db "\";")])]))
|
||||
[(psql-command config-w-template ["-c" (str "\"DROP DATABASE \\\"" pg-db "\\\";\"")])
|
||||
(psql-command config-w-template ["-c" (str "\"CREATE DATABASE \\\"" pg-db "\\\";\"")])]))
|
||||
|
|
|
@ -5,11 +5,10 @@
|
|||
[dda.backup.postgresql.domain :as cut]))
|
||||
|
||||
(st/instrument `cut/pgpass)
|
||||
(st/instrument `cut/db-drop-command)
|
||||
(st/instrument `cut/db-create-command)
|
||||
(st/instrument `cut/db-drop-create-command)
|
||||
|
||||
(deftest should-calculate-pgpass
|
||||
(is (= "localhost:5432:mydb:user:password\nlocalhost:5432:template1:user:password\n"
|
||||
(is (= "localhost:5432:mydb:user:password"
|
||||
(cut/pgpass {:restic-repository "repo"
|
||||
:backup-path "dir-at-repo"
|
||||
:pg-host "localhost"
|
||||
|
@ -18,21 +17,12 @@
|
|||
:pg-user "user"
|
||||
:pg-password "password"}))))
|
||||
|
||||
(deftest should-calculate-db-drop-command
|
||||
(deftest should-calculate-db-drop-create-command
|
||||
(is (= [["psql" "-d" "template1" "-h" "localhost" "-p" "5432" "-U" "user"
|
||||
"--no-password" "-c" "DROP DATABASE \"mydb\";"]]
|
||||
(cut/db-drop-command {:restic-repository "repo"
|
||||
:backup-path "dir-at-repo"
|
||||
:pg-host "localhost"
|
||||
:pg-port 5432
|
||||
:pg-db "mydb"
|
||||
:pg-user "user"
|
||||
:pg-password "password"}))))
|
||||
|
||||
(deftest should-calculate-db-create-command
|
||||
(is (= [["psql" "-d" "template1" "-h" "localhost" "-p" "5432" "-U" "user"
|
||||
"--no-password" "-c" "CREATE DATABASE \"mydb\";"]]
|
||||
(cut/db-create-command {:restic-repository "repo"
|
||||
"--no-password" "-c" "\"DROP DATABASE \\\"mydb\\\";\""]
|
||||
["psql" "-d" "template1" "-h" "localhost" "-p" "5432" "-U" "user"
|
||||
"--no-password" "-c" "\"CREATE DATABASE \\\"mydb\\\";\""]]
|
||||
(cut/db-drop-create-command {:restic-repository "repo"
|
||||
:backup-path "dir-at-repo"
|
||||
:pg-host "localhost"
|
||||
:pg-port 5432
|
||||
|
|
Loading…
Reference in a new issue