autocommit

This commit is contained in:
leo 2024-08-14 10:49:57 +05:00
parent 26e1b4bada
commit 3921dfc04e
7 changed files with 145 additions and 30 deletions

16
acme.sh
View File

@ -5,20 +5,24 @@ if [ "$(id -u)" != "0" ]; then
exit 0 exit 0
fi fi
ACME_FILE="/data/secrets/$SERVER_DOMAIN/letsencrypt/$SERVER_DOMAIN.acme.json" LE_DIR="/data/secrets/$SERVER_DOMAIN/letsencrypt"
BACKUP_DIR="/backups/acme" BACKUP_DIR="/backups/letsencrypt"
ARCHIVE_FILE="$BACKUP_DIR/$SERVER_DOMAIN.tar.gz" ARCHIVE_FILE="$BACKUP_DIR/$SERVER_DOMAIN.tar.gz"
# load ACME_BACKUP_PASSWORD # load ACME_BACKUP_PASSWORD
SECRETS_PATH=/data/secrets/$SERVER_DOMAIN/$SERVER_DOMAIN.env SECRETS_PATH=/data/secrets/$SERVER_DOMAIN/$SERVER_DOMAIN.env
source $SECRETS_PATH
trap 'echo -e "\033[31mSomething went wrong\033[0m"; exit 1' EXIT trap 'echo -e "\033[31macme.sh: Something went wrong\033[0m"; exit 1' EXIT
set -e set -e
export DEBIAN_FRONTEND=noninteractive export DEBIAN_FRONTEND=noninteractive
tar -czf - -C "$ACME_FILE" . | openssl enc -aes-256-cbc -e -out "$ARCHIVE_FILE" -pass pass:"$ACME_BACKUP_PASSWORD" -pbkdf2 -iter 100000 source $SECRETS_PATH
echo 'check BACKUP_DIR...'
mkdir -p "$BACKUP_DIR"
tar -czf - -C "$LE_DIR" . | openssl enc -aes-256-cbc -e -out "$ARCHIVE_FILE" -pass pass:"$ACME_BACKUP_PASSWORD" -pbkdf2 -iter 100000
trap - EXIT trap - EXIT
echo "All backups were made successfully. Outdated backups have been deleted" echo "$LE_DIR backuped successfully to $ARCHIVE_FILE"

18
files-all.sh Normal file
View File

@ -0,0 +1,18 @@
#!/bin/bash
if [ "$(id -u)" != "0" ]; then
echo -e "\033[31mThis script requires superuser rights\033[0m"
exit 0
fi
trap 'echo -e "\033[31mSomething went wrong\033[0m"; exit 1' ERR
set -e
export DEBIAN_FRONTEND=noninteractive
bash files.sh
bash acme.sh
bash cleaner.sh
trap - ERR
echo "All files backups were made successfully. Outdated backups have been deleted"

View File

@ -5,12 +5,12 @@ if [ "$(id -u)" != "0" ]; then
exit 0 exit 0
fi fi
trap 'echo -e "\033[31mSomething went wrong\033[0m"; exit 1' EXIT trap 'echo -e "\033[31mfiles.sh: Something went wrong\033[0m"; exit 1' ERR
set -e set -e
export DEBIAN_FRONTEND=noninteractive export DEBIAN_FRONTEND=noninteractive
BACKUP_LIST=/data/$SRV_START_DIR/backups.cfg BACKUP_LIST=/data/$SRV_START_DIR/config/backups.cfg
BACKUP_DIR="/backups/files" BACKUP_DIR="/backups/files"
# Checking the presence of a backups.list # Checking the presence of a backups.list
@ -19,7 +19,7 @@ if [ ! -f "$BACKUP_LIST" ]; then
exit 1 exit 1
fi fi
# Creating main directories (if not created) echo 'check BACKUP_DIR...'
mkdir -p "$BACKUP_DIR" mkdir -p "$BACKUP_DIR"
echo 'Creating files backup...' echo 'Creating files backup...'
@ -41,7 +41,6 @@ while IFS= read -r DIR; do
# Formation of the archive name # Formation of the archive name
BASENAME=$(basename "$DIR") BASENAME=$(basename "$DIR")
#TIMESTAMP=$(date +%Y%m%d%H%M%S)
TIMESTAMP=$(date +%d-%m-%Y_%H%M%S) TIMESTAMP=$(date +%d-%m-%Y_%H%M%S)
ARCHIVE_NAME="${BASENAME}_${TIMESTAMP}.tar.gz" ARCHIVE_NAME="${BASENAME}_${TIMESTAMP}.tar.gz"
@ -49,7 +48,7 @@ while IFS= read -r DIR; do
BACKUP_FOLDER="${BACKUP_DIR}/${BASENAME}" BACKUP_FOLDER="${BACKUP_DIR}/${BASENAME}"
mkdir -p "$BACKUP_FOLDER" mkdir -p "$BACKUP_FOLDER"
# Creating an archive echo 'Pack to tar.gz...'
tar -czf "${BACKUP_FOLDER}/${ARCHIVE_NAME}" -C "$(dirname "$DIR")" "$BASENAME" tar -czf "${BACKUP_FOLDER}/${ARCHIVE_NAME}" -C "$(dirname "$DIR")" "$BASENAME"
# Checking the success of the backup # Checking the success of the backup
@ -61,5 +60,5 @@ while IFS= read -r DIR; do
fi fi
done < "$BACKUP_LIST" done < "$BACKUP_LIST"
trap - EXIT trap - ERR
echo "The backup of all specified directories has been completed successfully." echo "The backup of all specified directories has been completed successfully"

35
mariadb-all.sh Normal file
View File

@ -0,0 +1,35 @@
#!/bin/bash
if [ "$(id -u)" != "0" ]; then
echo -e "\033[31mThis script requires superuser rights\033[0m"
exit 0
fi
SECRETS_PATH=/data/secrets/$SERVER_DOMAIN/$SERVER_DOMAIN.env
trap 'echo -e "\033[31mmariadb-all: Something went wrong\033[0m"; exit 1' ERR
set -e
export DEBIAN_FRONTEND=noninteractive
source $SECRETS_PATH
if [ -z "$MARIADB_ROOT_PASSWORD" ]; then
echo "Error: MARIADB_ROOT_PASSWORD is not set or is empty"
exit 1
fi
DOCKER_SERVICE_NAME=mariadb
MYSQL_USER=root
MYSQL_DATABASE=mysql
docker exec -i $DOCKER_SERVICE_NAME mariadb -u$MYSQL_USER -p$MARIADB_ROOT_PASSWORD $MYSQL_DATABASE -N -e "
SELECT s.SCHEMA_NAME
FROM information_schema.SCHEMATA s
WHERE SCHEMA_NAME NOT IN ('information_schema', 'mysql', 'performance_schema', 'sys');
" | while IFS= read -r dbname; do
bash mariadb.sh $dbname
done
trap - ERR
echo "All mariadb databases backuped successfully"

61
mariadb.sh Normal file
View File

@ -0,0 +1,61 @@
#!/bin/bash
if [ "$(id -u)" != "0" ]; then
echo -e "\033[31mThis script requires superuser rights\033[0m"
exit 0
fi
if [ -z "$1" ]; then
echo "Please provide the MYSQL_DB as argument"
exit 1
fi
SECRETS_PATH=/data/secrets/$SERVER_DOMAIN/$SERVER_DOMAIN.env
trap 'echo -e "\033[31mmariadb.sh: Something went wrong\033[0m"; exit 1' ERR
set -e
export DEBIAN_FRONTEND=noninteractive
source $SECRETS_PATH
if [ -z "$MARIADB_ROOT_PASSWORD" ]; then
echo "Error: MARIADB_ROOT_PASSWORD is not set or is empty"
exit 1
fi
MYSQL_DB="$1"
MYSQL_USER=root
CURRENT_MONTH=$(date +%Y-%m)
CURRENT_DATE=$(date +%Y-%m-%d)
CURRENT_DATETIME=$(date +%d-%m-%Y_%H%M%S)
BACKUPS_PATH=/backups/mariadb
DOCKER_SERVICE_NAME=mariadb
BACKUP_FOLDER=$BACKUPS_PATH/$PGDB
echo 'check BACKUP_FOLDER...'
mkdir -p "$BACKUP_FOLDER"
echo 'Creating mariadb backups...'
cd "$BACKUP_FOLDER"
if [ -f 'dump_'"$MYSQL_DB"'.sql' ]; then
rm 'dump_'"$MYSQL_DB"'.sql'
fi
DB_BACKUP_FILENAME=$MYSQL_DB'_'$CURRENT_DATETIME'.tar.gz'
echo 'Exec mysqldump...'
docker exec -t $DOCKER_SERVICE_NAME mysqldump -u $MYSQL_USER -p$MARIADB_ROOT_PASSWORD $MYSQL_DB > 'dump_'"$MYSQL_DB"'.sql'
echo 'Pack to tar.gz...'
tar -cf - 'dump_'"$MYSQL_DB"'.sql' | gzip -9 > "$DB_BACKUP_FILENAME"
rm 'dump_'"$MYSQL_DB"'.sql'
cd "$BACKUP_FOLDER"
echo 'Write md5 sum...'
md5sum * > MD5SUMS
trap - ERR
echo 'The backup of the '"$MYSQL_DB"' database was completed successfully'

View File

@ -5,7 +5,7 @@ if [ "$(id -u)" != "0" ]; then
exit 0 exit 0
fi fi
trap 'echo -e "\033[31mSomething went wrong\033[0m"; exit 1' EXIT trap 'echo -e "\033[31mpostgres-all.sh: Something went wrong\033[0m"; exit 1' ERR
set -e set -e
export DEBIAN_FRONTEND=noninteractive export DEBIAN_FRONTEND=noninteractive
@ -20,9 +20,5 @@ while IFS=, read -r dbname owner; do
bash postgres.sh "$dbname" "$owner" bash postgres.sh "$dbname" "$owner"
done done
bash files.sh trap - ERR
bash acme.sh echo "All postgres databases backuped successfully"
bash cleaner.sh
trap - EXIT
echo "All backups were made successfully. Outdated backups have been deleted"

View File

@ -10,42 +10,44 @@ if [ -z "$1" ] || [ -z "$2" ]; then
exit 1 exit 1
fi fi
trap 'echo -e "\033[31mSomething went wrong\033[0m"; exit 1' EXIT trap 'echo -e "\033[31mpostgres.sh: Something went wrong\033[0m"; exit 1' ERR
set -e set -e
export DEBIAN_FRONTEND=noninteractive export DEBIAN_FRONTEND=noninteractive
# configuration settings
PGDB="$1" PGDB="$1"
PGUSER="$2" PGUSER="$2"
CURRENT_MONTH=$(date +%Y-%m) CURRENT_MONTH=$(date +%Y-%m)
CURRENT_DATE=$(date +%Y-%m-%d) CURRENT_DATE=$(date +%Y-%m-%d)
#CURRENT_DATETIME=$(date +%d-%b-%Y_%H_%M_%Z)
CURRENT_DATETIME=$(date +%d-%m-%Y_%H%M%S) CURRENT_DATETIME=$(date +%d-%m-%Y_%H%M%S)
BACKUPS_PATH=/backups/postgres BACKUPS_PATH=/backups/postgres
DOCKER_SERVICE_NAME=postgres DOCKER_SERVICE_NAME=postgres
# backup PostgreSQL database
BACKUP_FOLDER=$BACKUPS_PATH/$PGDB BACKUP_FOLDER=$BACKUPS_PATH/$PGDB
if [ ! -d "$BACKUP_FOLDER" ]; then
mkdir -p "$BACKUP_FOLDER" echo 'check BACKUP_FOLDER...'
fi mkdir -p "$BACKUP_FOLDER"
echo 'Creating PostgreSQL backups...' echo 'Creating PostgreSQL backups...'
cd "$BACKUP_FOLDER" cd "$BACKUP_FOLDER"
if [ -f 'dump_'"$PGDB"'.sql' ]; then if [ -f 'dump_'"$PGDB"'.sql' ]; then
rm 'dump_'"$PGDB"'.sql' rm 'dump_'"$PGDB"'.sql'
fi fi
db_backup_filename=$PGDB'_'$CURRENT_DATETIME'.tar.gz' DB_BACKUP_FILENAME=$PGDB'_'$CURRENT_DATETIME'.tar.gz'
echo 'Exec pg_dump...'
docker exec -t postgres pg_dump -U $PGUSER $PGDB > 'dump_'"$PGDB"'.sql' docker exec -t postgres pg_dump -U $PGUSER $PGDB > 'dump_'"$PGDB"'.sql'
tar -cf - 'dump_'"$PGDB"'.sql' | gzip -9 > "$db_backup_filename" echo 'Pack to tar.gz...'
tar -cf - 'dump_'"$PGDB"'.sql' | gzip -9 > "$DB_BACKUP_FILENAME"
rm 'dump_'"$PGDB"'.sql' rm 'dump_'"$PGDB"'.sql'
cd "$BACKUP_FOLDER" cd "$BACKUP_FOLDER"
echo 'Write md5 sum...'
md5sum * > MD5SUMS md5sum * > MD5SUMS
trap - EXIT trap - ERR
echo 'The backup of the '"$PGDB"' database was completed successfully' echo 'The backup of the '"$PGDB"' database was completed successfully'