Skip to content

Instantly share code, notes, and snippets.

@wtser
Created April 18, 2015 01:17
Show Gist options
  • Save wtser/cdb9c14e95bf736cd126 to your computer and use it in GitHub Desktop.
Save wtser/cdb9c14e95bf736cd126 to your computer and use it in GitHub Desktop.
mysql 备份 Shell 脚本
#!/bin/sh
function backup(){
cd /var/tmp/
for databaseName in $*
do
sqlFileName=""$databaseName".sql"
echo "exporting "$databaseName
# 导出数据库
mysqldump -u user -ppassword $databaseName > sql/$sqlFileName
done
# 打包压缩
echo "正在打包"
tar zcvf sql.tar.gz sql/
# 远程拷贝
echo "正在发送到备份服务器"
scp sql.tar.gz [email protected]:/var/tmp/
}
backup 'site1.cn' 'site2.com'
# 恢复数据库
echo "正在恢复数据"
ssh [email protected] "bash /var/tmp/mysql_restore.sh"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment