#!/bin/bash
# step 1. backup mysql
cd /root/backup/
DATE_YYYYMMDDHHMMSS=`date '+%Y%m%d%H%M%S'`
dailysql=$DATE_YYYYMMDDHHMMSS'_daily.sql'
password='db password'
echo "mysql dailysql dump start.."
mysqldump -A -uroot -p$password --single-transaction > ./$dailysql
echo 'dumpfile : '$dailysql
tar cvzf ./$dailysql'.tar.gz' ./$dailysql
rm ./$dailysql
echo 'compression file : './$dailysql'.tar.gz'
echo "mysql dailysql dump done.."
# step 2. copy to other server...
sshpass -p '[비번]' scp -P [포트넘버] -o StrictHostKeyChecking=no ./$dailysql'.tar.gz' user@domain:/url/mysql-backup/