2021-04-25 21:39:11 +01:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
|
|
DATE=$(date -I)
|
|
|
|
BACKUP_DIR=$1
|
|
|
|
|
|
|
|
if [ -z "$BACKUP_DIR" ]
|
|
|
|
then
|
|
|
|
echo "No backup dir"
|
|
|
|
fi
|
|
|
|
|
|
|
|
all_containers=$(docker ps --format "{{.ID}}:{{ .Image }}")
|
|
|
|
|
|
|
|
for line in $all_containers
|
|
|
|
do
|
|
|
|
IFS=':' read -a container_details <<< $line
|
|
|
|
|
|
|
|
container_name=${container_details[1]}
|
|
|
|
container_id=${container_details[0]}
|
|
|
|
|
|
|
|
case "$container_name" in
|
|
|
|
"mariadb")
|
|
|
|
db_name=$(docker exec $container_id bash -c 'echo $MYSQL_USER')
|
2021-05-08 16:12:41 +01:00
|
|
|
echo Backing up mariadb $db_name
|
2021-05-16 11:16:25 +01:00
|
|
|
docker exec $container_id bash -c 'mysqldump -u $MYSQL_USER -p$MYSQL_PASSWORD --all-databases' | pv > $BACKUP_DIR/$db_name-$DATE.sql
|
2021-04-25 21:39:11 +01:00
|
|
|
;;
|
|
|
|
|
|
|
|
"postgres")
|
|
|
|
db_name=$(docker exec $container_id bash -c 'echo $POSTGRES_USER')
|
2021-05-08 16:12:41 +01:00
|
|
|
echo Backing up postgres $db_name
|
2021-05-16 11:16:25 +01:00
|
|
|
docker exec $container_id bash -c 'PGPASSWORD=$POSTGRES_PASSWORD pg_dumpall -U $POSTGRES_USER' | pv > $BACKUP_DIR/$db_name-$DATE.sql
|
2021-04-25 21:39:11 +01:00
|
|
|
;;
|
2021-05-16 12:25:32 +01:00
|
|
|
"yandex/clickhouse-server")
|
|
|
|
# Hardcode for plausible
|
|
|
|
tables=$(docker exec $container_id clickhouse-client --query "SELECT name FROM system.tables where database == 'plausible';")
|
|
|
|
for table in $tables
|
|
|
|
do
|
|
|
|
echo Backing up clickhouse table $table
|
|
|
|
docker exec $container_id clickhouse-client --query "SELECT * FROM plausible.$table" --format CSVWithNames | pv > $BACKUP_DIR/plausible-$table-$DATE.csv
|
|
|
|
done
|
|
|
|
;;
|
|
|
|
|
2021-04-25 21:39:11 +01:00
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
|
|
|
echo "Setting user permissions..."
|
|
|
|
chown -R root:root $BACKUP_DIR
|