docker.yml aktualisiert
This commit is contained in:
parent
dbd1a1959e
commit
69b7eb1990
28
docker.yml
28
docker.yml
@ -162,7 +162,7 @@
|
|||||||
marker: "# {mark} ANSIBLE MANAGED BLOCK"
|
marker: "# {mark} ANSIBLE MANAGED BLOCK"
|
||||||
block: |
|
block: |
|
||||||
### DB Backup
|
### DB Backup
|
||||||
g_echo_ok "Starte Backup von MySQL-Datenbanken (Docker)"
|
g_echo_ok "Starte Backup von MySQL und PostgreSQL Datenbanken (Docker)"
|
||||||
|
|
||||||
DAYS=7
|
DAYS=7
|
||||||
|
|
||||||
@ -170,6 +170,9 @@
|
|||||||
CONTAINER=$(docker ps --format \{\{.Names\}\}:\{\{.Image\}\}| grep 'mysql\|mariadb' | cut -d":" -f1 | grep -v mailcow)
|
CONTAINER=$(docker ps --format \{\{.Names\}\}:\{\{.Image\}\}| grep 'mysql\|mariadb' | cut -d":" -f1 | grep -v mailcow)
|
||||||
|
|
||||||
mkdir -p $BACKUPDIR
|
mkdir -p $BACKUPDIR
|
||||||
|
|
||||||
|
|
||||||
|
### MYSQL ###
|
||||||
for i in $CONTAINER
|
for i in $CONTAINER
|
||||||
do
|
do
|
||||||
# get credentials
|
# get credentials
|
||||||
@ -184,14 +187,33 @@
|
|||||||
g_echo_error "No dbdumpcmd found in container $i! No backup created!"
|
g_echo_error "No dbdumpcmd found in container $i! No backup created!"
|
||||||
continue
|
continue
|
||||||
fi
|
fi
|
||||||
g_echo "Sichere Datenbank $MARIADB_DATABASE DB aus $i";
|
g_echo "Sichere MySQL/MariaDB Datenbank $MARIADB_DATABASE DB aus $i";
|
||||||
docker exec $i $DBDUMPCMD --no-tablespaces -u $MARIADB_USR -p$MARIADB_PWD $MARIADB_DATABASE 2>${g_tmp}/dberr | gzip > $BACKUPDIR/$i-$MARIADB_DATABASE-$TIMESTAMP.sql.gz || g_echo_error "DB-Backup von $MARIADB_DATABASE war nicht erfolgreich $(cat ${g_tmp}/dberr)"
|
docker exec $i $DBDUMPCMD --no-tablespaces -u $MARIADB_USR -p$MARIADB_PWD $MARIADB_DATABASE 2>${g_tmp}/dberr | gzip > $BACKUPDIR/$i-$MARIADB_DATABASE-$TIMESTAMP.sql.gz || g_echo_error "DB-Backup von $MARIADB_DATABASE war nicht erfolgreich $(cat ${g_tmp}/dberr)"
|
||||||
# dont delete last old backups!
|
# dont delete last old backups!
|
||||||
OLD_BACKUPS=$(ls -1 $BACKUPDIR/$i*.gz |wc -l)
|
OLD_BACKUPS=$(ls -1 $BACKUPDIR/$i*.gz |wc -l)
|
||||||
if [ $OLD_BACKUPS -gt $DAYS ]; then
|
if [ $OLD_BACKUPS -gt $DAYS ]; then
|
||||||
find $BACKUPDIR -name "$i*.gz" -daystart -mtime +$DAYS -delete
|
find $BACKUPDIR -name "$i*.gz" -daystart -mtime +$DAYS -delete
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
|
### POSTGRESQL ##
|
||||||
|
CONTAINER=$(docker ps --format \{\{.Names\}\}:\{\{.Image\}\}| grep 'postgres' | cut -d":" -f1 | grep -v mailcow)
|
||||||
|
mkdir -p $BACKUPDIR
|
||||||
|
for i in $CONTAINER
|
||||||
|
do
|
||||||
|
# get credentials
|
||||||
|
POSTGRES_DATABASE=$(docker exec $i env | egrep "POSTGRES_DB" | tail -n1 |cut -d"=" -f2)
|
||||||
|
POSTGRES_PWD=$(docker exec $i env | egrep "POSTGRES_PASSWORD" | tail -n1 |cut -d"=" -f2)
|
||||||
|
POSTGRES_USR=$(docker exec $i env | egrep "POSTGRES_USER" | tail -n1 |cut -d"=" -f2)
|
||||||
|
# get dump path
|
||||||
|
g_echo "Sichere Datenbank $POSTGRES_DATABASE aus $i";
|
||||||
|
docker exec -e PGPASSWORD=$POSTGRES_PWD $i /usr/bin/pg_dump -U $POSTGRES_USR $POSTGRES_DATABASE 2>${g_tmp}/dberr | gzip > $BACKUPDIR/$i-$POSTGRES_DATABASE-$TIMESTAMP.sql.gz || g_echo_error "DB-Backup von $POSTGRES_DATABASE war nicht erfolgreich $(cat ${g_tmp}/dberr)"
|
||||||
|
# dont delete last old backups!
|
||||||
|
OLD_BACKUPS=$(ls -1 $BACKUPDIR/$i*.gz |wc -l)
|
||||||
|
if [ $OLD_BACKUPS -gt $DAYS ]; then
|
||||||
|
find $BACKUPDIR -name "$i*.gz" -daystart -mtime +$DAYS -delete
|
||||||
|
fi
|
||||||
|
done
|
||||||
backup: yes
|
backup: yes
|
||||||
validate: /bin/bash -n %s
|
validate: /bin/bash -n %s
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user