2023-09-05 14:31:41 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
filename="$(hostname) $(date +'%Y-%m-%d %H%M%S')"
|
|
|
|
skip_dbs=("mysql" "information_schema" "performance_schema" "sys")
|
|
|
|
tmpdir="/tmp/fw-db-backup"
|
|
|
|
workdir="$tmpdir/$filename"
|
2023-09-08 11:49:36 +00:00
|
|
|
|
2023-09-05 14:31:41 +00:00
|
|
|
mariadb_user=""
|
|
|
|
mariadb_pass=""
|
|
|
|
db_backups_depot="."
|
|
|
|
|
2023-09-08 11:49:36 +00:00
|
|
|
current_dir="$(dirname "$0")"
|
|
|
|
config_path="$current_dir/config.sh"
|
|
|
|
|
|
|
|
if [ ! -e "$config_path" ]; then
|
2023-09-05 14:31:41 +00:00
|
|
|
echo "config.sh not found, copy config.sh.example if you haven't yet"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2023-09-08 11:49:36 +00:00
|
|
|
source "$config_path"
|
2023-09-05 14:31:41 +00:00
|
|
|
|
|
|
|
echo "Resetting temp directory..."
|
|
|
|
rm -rf "$tmpdir"
|
|
|
|
mkdir -p "$workdir"
|
|
|
|
|
|
|
|
dbs=$(mysql -u "$mariadb_user" -p"$mariadb_pass" --skip-column-names -e "SHOW DATABASES")
|
|
|
|
|
|
|
|
for db in $dbs; do
|
|
|
|
if [[ " ${skip_dbs[@]} " =~ " $db " ]]; then
|
|
|
|
continue
|
|
|
|
fi
|
|
|
|
|
|
|
|
echo "Dumping $db.sql..."
|
|
|
|
mysqldump --default-character-set=utf8mb4 --single-transaction \
|
|
|
|
--tz-utc --triggers --routines --hex-blob --add-locks \
|
|
|
|
--order-by-primary --skip-lock-tables -QqB \
|
|
|
|
-u "$mariadb_user" -p"$mariadb_pass" \
|
|
|
|
--result-file="$workdir/$db.sql" $db
|
|
|
|
done;
|
|
|
|
|
|
|
|
echo "Creating package..."
|
|
|
|
tar -cjvf "$db_backups_depot/$filename.tar.bz2" -C "$tmpdir/" "$filename"
|
|
|
|
|
|
|
|
echo "Cleaning up..."
|
|
|
|
rm -r "$tmpdir"
|