From 94c84d714df7837ef177e828661d3713fb3934d8 Mon Sep 17 00:00:00 2001
From: tee <tee@mirai.hfbk.net>
Date: Tue, 14 Mar 2023 15:25:28 +0100
Subject: [PATCH] add old scripts from v2.4

---
 greenlight-dbshell                            |  2 ++
 greenlight-postgres-backup-greenlight-only    | 24 +++++++++++++++++
 ...nlight-postgres-backup-greenlight-only.nop | 25 +++++++++++++++++
 greenlight-postgres-restore-all               |  9 +++++++
 greenlight-postgres-restore-greenlight-only   | 27 +++++++++++++++++++
 greenlight-rails-shell                        |  2 ++
 6 files changed, 89 insertions(+)
 create mode 100755 greenlight-dbshell
 create mode 100755 greenlight-postgres-backup-greenlight-only
 create mode 100755 greenlight-postgres-backup-greenlight-only.nop
 create mode 100755 greenlight-postgres-restore-all
 create mode 100755 greenlight-postgres-restore-greenlight-only
 create mode 100755 greenlight-rails-shell

diff --git a/greenlight-dbshell b/greenlight-dbshell
new file mode 100755
index 0000000..da3e181
--- /dev/null
+++ b/greenlight-dbshell
@@ -0,0 +1,2 @@
+#!/bin/sh
+docker exec -itu postgres greenlight_db_1 psql $*
diff --git a/greenlight-postgres-backup-greenlight-only b/greenlight-postgres-backup-greenlight-only
new file mode 100755
index 0000000..8fc90c6
--- /dev/null
+++ b/greenlight-postgres-backup-greenlight-only
@@ -0,0 +1,24 @@
+#!/bin/bash
+# backup the greenlight postgres dbs
+# (c) 2020-2038 cc-by-nc-sa wotwot
+
+now=`date +%Y%m%d-%H%M`
+host=`hostname -s`
+file="postgres-${host}-${now}-greenlight-only.sql"
+dir="/var/backups/postgresql"
+dbname="greenlight_db_1"
+
+if [ ! -d "$dir" ] ; then
+	echo "no $dir, making one"
+	mkdir $dir
+fi
+
+cd /root/greenlight || \
+	{
+	echo "greenlight not found"
+	exit
+	}
+
+#docker ps || exit
+
+docker exec -u postgres ${dbname} pg_dump greenlight_production -c > ${dir}/${file}
diff --git a/greenlight-postgres-backup-greenlight-only.nop b/greenlight-postgres-backup-greenlight-only.nop
new file mode 100755
index 0000000..4086c01
--- /dev/null
+++ b/greenlight-postgres-backup-greenlight-only.nop
@@ -0,0 +1,25 @@
+#!/bin/bash
+# backup the greenlight postgres dbs
+# (c) 2020-2038 cc-by-nc-sa wotwot
+
+now=`date +%Y%m%d-%H%M`
+host=`hostname -s`
+file="postgres-${host}-${now}-greenlight-only.sql"
+dir="/var/backups/postgresql"
+dbname="greenlight_db_1"
+
+if [ ! -d "$dir" ] ; then
+	echo "no $dir, making one"
+	mkdir $dir
+fi
+
+cd /root/greenlight || \
+	{
+	echo "greenlight not found"
+	exit
+	}
+
+#docker ps || exit
+
+docker exec -u postgres ${dbname} pg_dumpall > ${dir}/${file}
+docker exec -u postgres ${dbname} pg_dump greenlight_production > ${dir}/${file}
diff --git a/greenlight-postgres-restore-all b/greenlight-postgres-restore-all
new file mode 100755
index 0000000..95a017a
--- /dev/null
+++ b/greenlight-postgres-restore-all
@@ -0,0 +1,9 @@
+#!/bin/sh
+file=$*
+if [ -z "$file" ] ; then
+	echo "ouch wot ?"
+	exit
+fi
+#	 docker exec -u postgres greenlight_db_1 psql postgres < ../bbb-postgres-20200514.sql
+#	 docker exec -u postgres greenlight_db_1 psql greenlight_production < ../bbb-greenlight_production-20200514.sql
+docker exec -u postgres greenlight_db_1 psql < $file
diff --git a/greenlight-postgres-restore-greenlight-only b/greenlight-postgres-restore-greenlight-only
new file mode 100755
index 0000000..64a8e07
--- /dev/null
+++ b/greenlight-postgres-restore-greenlight-only
@@ -0,0 +1,27 @@
+#!/bin/bash
+# restore a greenlight postgres db from a textdump
+# (c) 2020-2038 cc-by-nc-sa wotwot
+
+file=$1
+
+if [ -z "$file" ] ; then
+	echo "nah. tell me the full path to the file to replace the greenlight db with" > /dev/stderr
+	exit
+else
+	if [ ! -f "$file" ] ; then
+		echo "file not found" > /dev/stderr
+		exit
+	fi
+fi
+
+dbname="greenlight_db_1"
+
+cd /root/greenlight || \
+	{
+	echo "greenlight not found"
+	exit
+	}
+
+echo "docker exec -u postgres ${dbname} psql greenlight_production < $file"
+docker exec -u postgres ${dbname} psql greenlight_production < $file
+
diff --git a/greenlight-rails-shell b/greenlight-rails-shell
new file mode 100755
index 0000000..8aade0c
--- /dev/null
+++ b/greenlight-rails-shell
@@ -0,0 +1,2 @@
+#!/bin/sh
+docker exec -it  greenlight-v2 bash
-- 
GitLab