#!/bin/bash

dbUser=$1
dbPassword=$2
dbHost=$3
dbPort=$4
dbName=$5
backUpPath=$6
ossPath=$7

protal=obs

PATH=PATH:/usr/bin:/usr/sbin:/usr/local/bin

cd $backUpPath
/usr/bin/mysqldump -R --opt --protocol=TCP --user=${dbUser} --password=${dbPassword} --host=${dbHost} --port=${dbPort} ${dbName}  > ${backUpPath}/${dbName}.sql

cd $backUpPath
rm ${dbName}.sql_bak3.tar.gz
mv ${dbName}.sql_bak2.tar.gz ${dbName}.sql_bak3.tar.gz
mv ${dbName}.sql_bak1.tar.gz ${dbName}.sql_bak2.tar.gz
mv ${dbName}.sql.tar.gz ${dbName}.sql_bak1.tar.gz
rm sql -fr || true
mkdir sql
mv ${dbName}.sql sql
tar -czvf ${dbName}.sql.tar.gz sql

echo "ossPath: "${ossPath}
ossutil cp ${dbName}.sql.tar.gz ${protol}://${ossPath}/ -f