#!/bin/bash#Sync the database from local to remote, using a secure tunnel.auth_timeout=15# ssh will take a little time to authenticatessh -C -N -L 6603:gallery.db:3306 me@remote &tunnel_pid=$!function closeTunnel{ kill -15 $tunnel_pid}# wait until authentication is completeuntil $(netstat -antp 2>&1 | grep -q '127\.0\.0\.1:6603\b.*\b'$tunnel_pid'/ssh') ; do sleep 1 auth_timeout=$(($auth_timeout-1)) if (( $auth_timeout <= 0 )) ; then echo 'Could not establish tunnel.' 1>&2 closeTunnel exit 1 fidone# run the synchronizermysqldump --defaults-file=./mysql-gallery.cnf --opt --skip-quick kphotoalbum | mysql --defaults-file=./mysql-gallery.cnf --compress --host=gallery.db --port=6603 kphotoalbum# close the tunnelcloseTunnel