#!/bin/sh

db_url="mysql://user:password@host/database"
ssh_url="ssh://user:@host"

db_name=`echo $db_url | cut -f4 -d/`
db_user=`echo $db_url | cut -f3 -d/ | cut -f1 -d:`
db_pass=`echo $db_url | cut -f3 -d/ | cut -f2 -d: | cut -f1 -d@`
db_host=`echo $db_url | cut -f3 -d/ | cut -f2 -d: | cut -f2 -d@`

ssh_user=`echo $ssh_url | cut -f3 -d/ | cut -f1 -d:`
ssh_host=`echo $ssh_url | cut -f3 -d/ | cut -f2 -d: | cut -f2 -d@`

ssh $ssh_user@$ssh_host "mysqldump -h $db_host -u $db_user -p$db_pass $db_name | gzip -c" > $db_name-`date "+%Y%m%d-%H%M%S"`.sql.gz

