Improved Plan B scripts (dumps).

This commit is contained in:
Christian P. MOMON 2023-03-20 23:43:59 +01:00
parent ee17a9685d
commit 3a84710354
4 changed files with 72 additions and 0 deletions

19
Plan Borg/bin/dump-influx Executable file
View File

@ -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

18
Plan Borg/bin/dump-msql Executable file
View File

@ -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

21
Plan Borg/bin/dump-psql Executable file
View File

@ -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

14
Plan Borg/bin/dumps Executable file
View File

@ -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