Compare commits
2 commits
2b2f2294ae
...
1dac340644
Author | SHA1 | Date | |
---|---|---|---|
1dac340644 | |||
6eef7c911f |
6 changed files with 34 additions and 16 deletions
|
@ -2,5 +2,6 @@ FROM ubuntu:24.04
|
||||||
|
|
||||||
# install it
|
# install it
|
||||||
ADD resources /tmp/
|
ADD resources /tmp/
|
||||||
ADD local/ /usr/local/lib/dda-backup
|
|
||||||
RUN /tmp/install.sh
|
RUN /tmp/install.sh
|
||||||
|
ADD local/ /usr/local/lib/dda-backup
|
||||||
|
RUN init-bb.bb
|
||||||
|
|
|
@ -15,7 +15,7 @@ function babashka_install() {
|
||||||
function main() {
|
function main() {
|
||||||
{
|
{
|
||||||
upgradeSystem
|
upgradeSystem
|
||||||
apt-get install -qqy ca-certificates curl gnupg postgresql-client-16 restic openjdk-21-jre-headless
|
apt-get install -qqy ca-certificates curl gnupg postgresql-client-16 restic openjdk-21-jre-headless nano
|
||||||
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
|
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'
|
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
|
upgradeSystem
|
||||||
|
@ -23,8 +23,7 @@ function main() {
|
||||||
} > /dev/null
|
} > /dev/null
|
||||||
|
|
||||||
update-ca-certificates
|
update-ca-certificates
|
||||||
/tmp/init.bb
|
install -m 0700 -o root -g root /tmp/init-bb.bb /usr/local/bin/
|
||||||
|
|
||||||
cleanupDocker
|
cleanupDocker
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -27,4 +27,6 @@
|
||||||
(defn-spec drop-create-db! nil?
|
(defn-spec drop-create-db! nil?
|
||||||
[config ::pg-config]
|
[config ::pg-config]
|
||||||
(let [config-w-defaults (merge default config)]
|
(let [config-w-defaults (merge default config)]
|
||||||
(i/execute! (domain/db-drop-create-command config-w-defaults) config-w-defaults)))
|
(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)))
|
||||||
|
|
|
@ -68,11 +68,17 @@
|
||||||
(defn-spec pgpass string?
|
(defn-spec pgpass string?
|
||||||
[config ::pg-config]
|
[config ::pg-config]
|
||||||
(let [{:keys [pg-host pg-port pg-db pg-user pg-password]} 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)))
|
(str pg-host ":" pg-port ":" pg-db ":" pg-user ":" pg-password "\n"
|
||||||
|
pg-host ":" pg-port ":template1:" pg-user ":" pg-password "\n")))
|
||||||
|
|
||||||
(defn-spec db-drop-create-command ::cd/commands
|
(defn-spec db-drop-command ::cd/commands
|
||||||
[config ::pg-config]
|
[config ::pg-config]
|
||||||
(let [{:keys [pg-db]} config
|
(let [{:keys [pg-db]} config
|
||||||
config-w-template (merge config {:pg-db "template1"})]
|
config-w-template (merge config {:pg-db "template1"})]
|
||||||
[(psql-command config-w-template ["-c" (str "\"DROP 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 "\\\";\"")])]))
|
|
||||||
|
(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 "\";")])]))
|
|
@ -5,10 +5,11 @@
|
||||||
[dda.backup.postgresql.domain :as cut]))
|
[dda.backup.postgresql.domain :as cut]))
|
||||||
|
|
||||||
(st/instrument `cut/pgpass)
|
(st/instrument `cut/pgpass)
|
||||||
(st/instrument `cut/db-drop-create-command)
|
(st/instrument `cut/db-drop-command)
|
||||||
|
(st/instrument `cut/db-create-command)
|
||||||
|
|
||||||
(deftest should-calculate-pgpass
|
(deftest should-calculate-pgpass
|
||||||
(is (= "localhost:5432:mydb:user:password"
|
(is (= "localhost:5432:mydb:user:password\nlocalhost:5432:template1:user:password\n"
|
||||||
(cut/pgpass {:restic-repository "repo"
|
(cut/pgpass {:restic-repository "repo"
|
||||||
:backup-path "dir-at-repo"
|
:backup-path "dir-at-repo"
|
||||||
:pg-host "localhost"
|
:pg-host "localhost"
|
||||||
|
@ -17,12 +18,21 @@
|
||||||
:pg-user "user"
|
:pg-user "user"
|
||||||
:pg-password "password"}))))
|
:pg-password "password"}))))
|
||||||
|
|
||||||
(deftest should-calculate-db-drop-create-command
|
(deftest should-calculate-db-drop-command
|
||||||
(is (= [["psql" "-d" "template1" "-h" "localhost" "-p" "5432" "-U" "user"
|
(is (= [["psql" "-d" "template1" "-h" "localhost" "-p" "5432" "-U" "user"
|
||||||
"--no-password" "-c" "\"DROP DATABASE \\\"mydb\\\";\""]
|
"--no-password" "-c" "DROP DATABASE \"mydb\";"]]
|
||||||
["psql" "-d" "template1" "-h" "localhost" "-p" "5432" "-U" "user"
|
(cut/db-drop-command {:restic-repository "repo"
|
||||||
"--no-password" "-c" "\"CREATE DATABASE \\\"mydb\\\";\""]]
|
:backup-path "dir-at-repo"
|
||||||
(cut/db-drop-create-command {:restic-repository "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"
|
||||||
:backup-path "dir-at-repo"
|
:backup-path "dir-at-repo"
|
||||||
:pg-host "localhost"
|
:pg-host "localhost"
|
||||||
:pg-port 5432
|
:pg-port 5432
|
||||||
|
|
Loading…
Reference in a new issue