From 3a84710354675e0b84a45cc7f78309859af36c70 Mon Sep 17 00:00:00 2001 From: "Christian P. MOMON" Date: Mon, 20 Mar 2023 23:43:59 +0100 Subject: [PATCH] Improved Plan B scripts (dumps). --- Plan Borg/bin/dump-influx | 19 +++++++++++++++++++ Plan Borg/bin/dump-msql | 18 ++++++++++++++++++ Plan Borg/bin/dump-psql | 21 +++++++++++++++++++++ Plan Borg/bin/dumps | 14 ++++++++++++++ 4 files changed, 72 insertions(+) create mode 100755 Plan Borg/bin/dump-influx create mode 100755 Plan Borg/bin/dump-msql create mode 100755 Plan Borg/bin/dump-psql create mode 100755 Plan Borg/bin/dumps diff --git a/Plan Borg/bin/dump-influx b/Plan Borg/bin/dump-influx new file mode 100755 index 0000000..024f9ad --- /dev/null +++ b/Plan Borg/bin/dump-influx @@ -0,0 +1,19 @@ +#!/bin/bash + +DUMP_DIR="/var/backups/dumps/" + +mkdir -p "$DUMP_DIR" +chmod go-rwx "$DUMP_DIR" + +if [ -x /usr/bin/influxd ]; then + DATABASES=$(influx --execute "show databases" | tail +4) + + echo "Databases: $DATABASES" + for DATABASE in $DATABASES ; do + echo "Dumping database: $DATABASE" + rm -fr "${DUMP_DIR}/influx-${DATABASE}" + /usr/bin/influxd backup -portable -database $DATABASE -host localhost:8088 $DUMP_DIR/influx-$DATABASE + done +else + echo "DMBS Influx not detected." +fi diff --git a/Plan Borg/bin/dump-msql b/Plan Borg/bin/dump-msql new file mode 100755 index 0000000..7f6e4bc --- /dev/null +++ b/Plan Borg/bin/dump-msql @@ -0,0 +1,18 @@ +#!/bin/bash +DUMP_DIR="/var/backups/dumps/" + +mkdir -p "$DUMP_DIR" +chmod go-rwx "$DUMP_DIR" + +if [ -x /usr/bin/mariadb-dump ]; then + # + DATABASES=$(mysql --defaults-file=/etc/mysql/debian.cnf -B -N --execute="SHOW DATABASES" | grep -v 'lost+found\|performance_schema\|information_schema') + + echo "Databases: $DATABASES" + for DATABASE in $DATABASES ; do + echo "Dumping database: $DATABASE" + /usr/bin/mariadb-dump --defaults-file=/etc/mysql/debian.cnf --single-transaction --quick --events $DATABASE | bzip2 - > $DUMP_DIR/$DATABASE-msql.sql.bz2 + done +else + echo "DMBS MariaDB not detected." +fi diff --git a/Plan Borg/bin/dump-psql b/Plan Borg/bin/dump-psql new file mode 100755 index 0000000..4008848 --- /dev/null +++ b/Plan Borg/bin/dump-psql @@ -0,0 +1,21 @@ +#!/bin/bash + +DUMP_DIR="/var/backups/dumps/" + +mkdir -p "$DUMP_DIR" +chmod go-rwx "$DUMP_DIR" + +if [ -x /usr/bin/psql ]; then + # + su - postgres -c "pg_dumpall --roles-only " | bzip2 > $DUMP_DIR/roles-psql.sql.bz2 + + # + DATABASES=$(su - postgres -c "psql -t -c \"SELECT datname FROM pg_database AS dbs INNER JOIN pg_authid AS roles ON dbs.datdba=roles.oid WHERE rolname<>'postgres' ;\"") + echo "Databases: $DATABASES" + for DATABASE in $DATABASES ; do + echo "Dumping database: $DATABASE" + su - postgres -c "pg_dump $DATABASE" | bzip2 - > $DUMP_DIR/$DATABASE-psql.sql.bz2 + done +else + echo "DMBS Postgresql not detected." +fi diff --git a/Plan Borg/bin/dumps b/Plan Borg/bin/dumps new file mode 100755 index 0000000..cae1cac --- /dev/null +++ b/Plan Borg/bin/dumps @@ -0,0 +1,14 @@ +#!/bin/bash + +BINDIR=$(dirname "$0") +cd "$BINDIR" + +DUMP_DIR="/var/backups/dumps/" + +if [ $(find "$DUMP_DIR" -cmin -120 -type d | wc -l) -eq 0 ]; then + ./dump-psql + ./dump-msql + ./dump-influx +else + echo "Very recent dump detected, dumps skipped." +fi