#!/bin/bash
TARGET_FILE=backupdb.sql
TAR_FILE=backupdb.tar.gz
printf "Dumping database\n"

if test -f "$TARGET_FILE"
then
  echo "Removing $TARGET_FILE"
  sudo rm "$TARGET_FILE"
fi
if test -f "$TAR_FILE"
then
  echo "Removing $TAR_FILE"
  sudo rm "$TAR_FILE"
fi
echo "Creating $TARGET_FILE"
#mysqldump --hex-blob --max_allowed_packet=64M --default-character-set=utf8mb4 --databases market_data portfolio_data user_data --user=root --password=dbas --master-data > "$TARGET_FILE"
mysqldump --hex-blob --max_allowed_packet=64M --default-character-set=utf8mb4 --databases market_data portfolio_data user_data --user=root --password=dbas --master-data | pv >  "$TARGET_FILE"
echo "Creating $TAR_FILE"
tar -czvf "$TAR_FILE" "$TARGET_FILE"
