Created
April 18, 2015 01:17
-
-
Save wtser/cdb9c14e95bf736cd126 to your computer and use it in GitHub Desktop.
mysql 备份 Shell 脚本
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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