From fddcdfd8862bf55d8cd9798e696ccc159a3107dd Mon Sep 17 00:00:00 2001 From: kristoferlund Date: Thu, 28 Jul 2022 11:28:02 +0200 Subject: [PATCH] Upgraded server scripts --- database-backup.sh | 3 +++ database-restore.sh | 11 +++++++++++ reset.sh | 20 ++++++++++++++++++++ restart.sh | 3 +++ setup.sh | 9 ++++++++- start.sh | 1 + upgrade.sh | 1 + 7 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 database-backup.sh create mode 100644 database-restore.sh create mode 100644 reset.sh create mode 100644 restart.sh diff --git a/database-backup.sh b/database-backup.sh new file mode 100644 index 000000000..3077247b5 --- /dev/null +++ b/database-backup.sh @@ -0,0 +1,3 @@ +#!/bin/bash +export $(grep -v '^#' .env | xargs) +docker exec -i mongodb-praise /usr/bin/mongodump --authenticationDatabase admin --archive -u $MONGO_INITDB_ROOT_USERNAME -p $MONGO_INITDB_ROOT_PASSWORD --db praise_db > database-backup-$(date +"%F-%T").archive \ No newline at end of file diff --git a/database-restore.sh b/database-restore.sh new file mode 100644 index 000000000..ce6f3e59e --- /dev/null +++ b/database-restore.sh @@ -0,0 +1,11 @@ +#!/bin/bash +if ! test -f "$1" ; then + echo "Could not find database backup" + echo "Usage: database-restore.sh filename\n" +fi +export $(grep -v '^#' .env | xargs) +docker compose -f ./docker-compose.production.yml down +docker volume rm $(docker volume ls -q) +docker compose -f ./docker-compose.production.yml up mongodb -d --remove-orphans +docker exec -i mongodb-praise sh -c 'mongorestore --authenticationDatabase admin -u $MONGO_INITDB_ROOT_USERNAME -p $MONGO_INITDB_ROOT_PASSWORD --nsInclude=praise_db.* --archive' < $1 +docker compose -f ./docker-compose.production.yml up -d --remove-orphans \ No newline at end of file diff --git a/reset.sh b/reset.sh new file mode 100644 index 000000000..3c3f60da6 --- /dev/null +++ b/reset.sh @@ -0,0 +1,20 @@ +#!/bin/bash +echo +echo "⚠ Running this script will delete ALL Praise data!" +read -p "Are you sure? (N/y) " -n 1 -r +echo +if [[ $REPLY =~ ^[Yy]$ ]] +then + echo + echo "Shutting down containers..." + echo + docker compose -f ./docker-compose.production.yml down + echo + echo "Deleting images..." + echo + docker rmi -f $(docker images -aq) + echo + echo "Deleting volumes..." + echo + docker volume rm $(docker volume ls -q) +fi diff --git a/restart.sh b/restart.sh new file mode 100644 index 000000000..3c3b8937c --- /dev/null +++ b/restart.sh @@ -0,0 +1,3 @@ +#!/bin/bash +docker compose -f ./docker-compose.production.yml down +docker compose -f ./docker-compose.production.yml up \ No newline at end of file diff --git a/setup.sh b/setup.sh index c73c9c9ab..f03d68369 100644 --- a/setup.sh +++ b/setup.sh @@ -1,2 +1,9 @@ -docker build -t praise-setup -f ./packages/setup/Dockerfile . +#!/bin/bash +IMAGE=$( docker images | grep praise-setup ) +if [ -z "$IMAGE" ] +then + echo "Building setup image..." + docker build -t praise-setup -q -f ./packages/setup/Dockerfile . +fi + docker run -it -v $(pwd):/usr/praise praise-setup \ No newline at end of file diff --git a/start.sh b/start.sh index b1790b476..6c346fa53 100644 --- a/start.sh +++ b/start.sh @@ -1 +1,2 @@ +#!/bin/bash docker compose -f ./docker-compose.production.yml up -d \ No newline at end of file diff --git a/upgrade.sh b/upgrade.sh index 851b44cfe..f259f9922 100644 --- a/upgrade.sh +++ b/upgrade.sh @@ -1,3 +1,4 @@ +#!/bin/bash docker compose -f ./docker-compose.production.yml pull docker compose -f ./docker-compose.production.yml down docker compose -f ./docker-compose.production.yml up -d --remove-orphans \ No newline at end of file