From 443c221ff191ffa9da88012696ffda82fde15ae3 Mon Sep 17 00:00:00 2001
From: m33 <m33>
Date: Mon, 27 Dec 2021 18:16:28 +0000
Subject: [PATCH] load scripts

---
 backup_postgres.sh  | 28 ++++++++++++++++++++++++++++
 cleanup_docker.sh   |  7 +++++++
 get_container_id.sh |  6 ++++++
 3 files changed, 41 insertions(+)
 create mode 100755 backup_postgres.sh
 create mode 100755 cleanup_docker.sh
 create mode 100755 get_container_id.sh

diff --git a/backup_postgres.sh b/backup_postgres.sh
new file mode 100755
index 0000000..b7faace
--- /dev/null
+++ b/backup_postgres.sh
@@ -0,0 +1,28 @@
+#!/bin/bash
+#
+# A daily backup for your docker postgresql database, run it daily
+# It will cycle with the day of week (1..7)
+#
+DT=`date +%w`
+
+### You will need to adjust DST and DOCKER_ENV Paths ###
+# Backup destination directory
+DST=/usr/local/backup
+# Docker env file from Misskey
+DOCKER_ENV=/usr/local/misskey/data/.config/docker.env
+###
+
+source $DOCKER_ENV || exit 1
+
+mkdir -p $DST
+cd $DST || exit 1
+
+# Get the posgres container ID
+pgcont=`get_container_id.sh postgres` || exit 1
+
+# Dump quick, compress later
+docker exec -i $pgcont pg_dump -U $POSTGRES_USER $POSTGRES_DB > backup-$POSTGRES_DB.$DT.pgsql
+
+nice xz --force backup-$POSTGRES_DB.$DT.pgsql
+
+exit $?
diff --git a/cleanup_docker.sh b/cleanup_docker.sh
new file mode 100755
index 0000000..c05272b
--- /dev/null
+++ b/cleanup_docker.sh
@@ -0,0 +1,7 @@
+#!/bin/bash
+#
+# Prune all orphaned images, and stopped containers
+#
+docker container prune
+docker image prune -a
+exit $?
diff --git a/get_container_id.sh b/get_container_id.sh
new file mode 100755
index 0000000..f36be05
--- /dev/null
+++ b/get_container_id.sh
@@ -0,0 +1,6 @@
+#!/bin/bash
+#
+# Get container ID from name
+#
+docker container ls|grep "$1"|awk '{print $1}'|grep -v CONTAINER
+exit $?
-- 
GitLab