From fcf7d1c98e3abff76e4152281f12014280000ae5 Mon Sep 17 00:00:00 2001 From: Alexander Barton Date: Tue, 4 Aug 2015 14:09:07 +0200 Subject: [PATCH] Add optional compression: --gzip|--bzip2|--xz --- bin/mkmysqldump | 32 +++++++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/bin/mkmysqldump b/bin/mkmysqldump index 4093768..80c299e 100755 --- a/bin/mkmysqldump +++ b/bin/mkmysqldump @@ -12,6 +12,7 @@ MYUSER="root" MYPW="" OUTFILE="$(hostname -s)-$(date "+%Y%m%d-%H%M%S").sql" STATS="" +COMPRESS="" Help() { echo "$NAME [ ...]" @@ -28,6 +29,12 @@ Help() { echo " Directory for automatically named dump files." echo " --summary|-s" echo " Display file and file system status summary." + echo " --gzip" + echo " Compress SQL dump file using gzip(1)" + echo " --bzip2" + echo " Compress SQL dump file using bzip2(1)" + echo " --xz" + echo " Compress SQL dump file using xz(1)" echo } @@ -70,6 +77,18 @@ while [ $# -gt 0 ]; do OUTFILE="$2/$(hostname -s)-$(date "+%Y%m%d-%H%M%S").sql" shift 2 ;; + "--gzip") + COMPRESS="gzip -v" + shift + ;; + "--bzip2") + COMPRESS="bzip2 -v" + shift + ;; + "--xz") + COMPRESS="xz -v" + shift + ;; "--summary"|"-s") STATS=1 shift @@ -113,14 +132,21 @@ CMD="mysqldump \ echo "Start date: $(date)" echo $CMD $CMD >"$OUTFILE"; r=$? +if [ -n "$COMPRESS" -a -s "$OUTFILE" -a $r -eq 0 ]; then + echo "Dump done: $(date)" + echo "Compressing dump file ($COMPRESS) ..." + $COMPRESS "$OUTFILE" +fi echo "End: $(date)" echo -if [ -e "$OUTFILE" -a -n "$STATS" ]; then +if [ -n "$STATS" ]; then echo "SQL dump file" - ls -lh "$OUTFILE" + for f in "$OUTFILE"*; do + ls -lh "$f"* + done echo - df -h "$OUTFILE" + df -h "$(dirname "$OUTFILE")" echo fi -- 2.39.2