basic db backup script

This commit is contained in:
Daniel O'Connell 2021-03-10 20:05:02 +01:00
parent 9a79be1f78
commit 67464f1d46
10 changed files with 45 additions and 23 deletions

5
.gitignore vendored
View File

@ -1,3 +1,8 @@
backend/.cpcache/
backend/.nrepl-port
backend/chicken-master.jar
frontend/.cpcache/
/frontend/out/
/frontend/resources/public/js
/frontend/resources/public/css

View File

@ -11,13 +11,7 @@ See the READMEs in the `backend` and `frontend` folders.
* daily view
* infinite scroll
* Move to different day
* handle regular customers
** every n days
** copy over to next week
** cancel regular order
* settings menu
* products CRM

View File

@ -20,4 +20,4 @@ The API for the chickens service.
## Deployment
clojure -X:depstar uberjar
java -jar chickens.jar -Dconfig=config/dev/config.edn
java -Dconfig=config/dev/config.edn -jar chickens.jar

View File

@ -1,13 +1,13 @@
{:paths ["src" "resources"]
:deps {org.clojure/clojure {:mvn/version "1.10.1"}
ns-tracker {:mvn/version "0.4.0"}
compojure {:mvn/version "1.6.2"}
ns-tracker/ns-tracker {:mvn/version "0.4.0"}
compojure/compojure {:mvn/version "1.6.2"}
yogthos/config {:mvn/version "1.1.7"}
seancorfield/next.jdbc {:mvn/version "1.1.613"}
org.postgresql/postgresql {:mvn/version "42.2.6"}
ring-basic-authentication {:mvn/version "1.1.0"}
ring-cors {:mvn/version "0.1.13"}
ring {:mvn/version "1.8.1"}}
ring-basic-authentication/ring-basic-authentication {:mvn/version "1.1.0"}
ring-cors/ring-cors {:mvn/version "0.1.13"}
ring/ring {:mvn/version "1.8.1"}}
:aliases
{:dev {:jvm-opts ["-Dconfig=config/dev/config.edn"]
@ -20,4 +20,4 @@
:depstar {:replace-deps
{com.github.seancorfield/depstar {:mvn/version "2.0.193"}}
:ns-default hf.depstar
:exec-args {:aot true :jar "chickens.jar" :main-class chicken-master.server}}}}
:exec-args {:aot true :jar "chicken-master.jar" :main-class chicken-master.server}}}}

View File

@ -3,7 +3,7 @@
[chicken-master.api :as endpoints]
[clojure.edn :as edn]
[config.core :refer [env]]
[compojure.core :refer [GET defroutes routes]]
[compojure.core :refer [GET defroutes routes context]]
[compojure.route :refer [resources not-found]]
[compojure.handler :refer [api]]
[ring.util.response :refer [resource-response]]
@ -39,11 +39,12 @@
(not-found "not found"))
(def handler (routes
(context "/api" []
(-> endpoints/all-routes
(wrap-basic-authentication authenticated?)
(wrap-cors :access-control-allow-origin (map re-pattern (env :allow-origin))
:access-control-allow-methods [:get :put :post :delete :options])
api
wrap-edn-request
wrap-edn-response)
wrap-edn-response))
base-routes))

14
deploy.sh Executable file
View File

@ -0,0 +1,14 @@
cd backend
clojure -X:depstar uberjar
cd ../frontend
npx shadow-cljs release frontend
clojure -A:garden -m chicken-master.css
cd ..
scp backend/chicken-master.jar chickens:/srv/chickens/chicken-master.jar
ssh chickens 'mkdir -p /srv/chickens/frontend/js'
ssh chickens 'mkdir -p /srv/chickens/frontend/css'
rsync -r frontend/resources/public/index.html chickens:/srv/chickens/frontend/index.html
rsync -r frontend/resources/public/css/screen.css chickens:/srv/chickens/frontend/css/screen.css
rsync -r frontend/resources/public/js/app.js chickens:/srv/chickens/frontend/js/app.js

View File

View File

@ -33,7 +33,7 @@
:editable-number-inputs (get-setting :editable-number-inputs false) ; only allow number modifications in the edit modal
:hide-fulfilled-orders (get-setting :hide-fulfilled-orders false)
:backend-url (get-setting :backend-url (.. js/window -location -href)) ; "http://localhost:3000/"
:backend-url (get-setting :backend-url (str (.. js/window -location -href) "api/")) ; "http://localhost:3000/"
})

View File

@ -3,7 +3,7 @@ Description=Chicken master
After=postgresql.service
[Service]
ExecStart=/usr/bin/java -Dconfig="/home/dan/chicken-master/config.edn" -jar /home/dan/chicken-master/target/chicken-master.jar
ExecStart=/usr/bin/java -Dconfig="/srv/chickens/config.edn" -jar /srv/chickens/chicken-master.jar
Type=simple
Restart=always
RestartSec=1

8
infra/db/pg_backup.sh Executable file
View File

@ -0,0 +1,8 @@
#!/bin/bash
DB_URI="postgresql://localhost/chickens?user=chicken_user&password="
BACKUP_DIR=/srv/chickens/backups/
BACKUP_FILE=$BACKUP_DIR"`date +\%Y-\%m-\%d`.sql"
pg_dump -Fp "$DB_URI" | gzip > $BACKUP_FILE.gz