如何遠程清理Production上48組MySQL DB Server上面的過期失效的備份 如何遠程清理48組MySQL DB Server上面的過期實效的備份! 剛開始想到一個個從control控制機器ssh進去,rm 掉,然後exit,再通過control機器ssh進去,再rm再exit,這樣的話豈不是要操作48次ssh以及exit,48台還能接受,如果是480台,4800台呢,any way ? OK,我想到了,寫一個shell腳本,在control機器上面遠程執行ssh命令,不需要ssh進具體的單台db了,如下clean.sh [html] ssh aaaaaaaaa048xxxxxx "sudo -u mysql du -sh /mysqlback/*"; ssh aaaaaaaaa047xxxxxx "sudo -u mysql du -sh /mysqlback/*"; ssh aaaaaaaaa046xxxxxx "sudo -u mysql du -sh /mysqlback/*"; ssh aaaaaaaaa045xxxxxx "sudo -u mysql du -sh /mysqlback/*"; ssh aaaaaaaaa044xxxxxx "sudo -u mysql du -sh /mysqlback/*"; ssh aaaaaaaaa043xxxxxx "sudo -u mysql du -sh /mysqlback/*"; ssh aaaaaaaaa042xxxxxx "sudo -u mysql du -sh /mysqlback/*"; ssh aaaaaaaaa041xxxxxx "sudo -u mysql du -sh /mysqlback/*"; ssh aaaaaaaaa040xxxxxx "sudo -u mysql du -sh /mysqlback/*"; ssh aaaaaaaaa039xxxxxx "sudo -u mysql du -sh /mysqlback/*"; ssh aaaaaaaaa038xxxxxx "sudo -u mysql du -sh /mysqlback/*"; ssh aaaaaaaaa037xxxxxx "sudo -u mysql du -sh /mysqlback/*"; ssh aaaaaaaaa036xxxxxx "sudo -u mysql du -sh /mysqlback/*"; ssh aaaaaaaaa035xxxxxx "sudo -u mysql du -sh /mysqlback/*"; ssh aaaaaaaaa034xxxxxx "sudo -u mysql du -sh /mysqlback/*"; ssh aaaaaaaaa033xxxxxx "sudo -u mysql du -sh /mysqlback/*"; ssh aaaaaaaaa032xxxxxx "sudo -u mysql du -sh /mysqlback/*"; ssh aaaaaaaaa031xxxxxx "sudo -u mysql du -sh /mysqlback/*"; ssh aaaaaaaaa030xxxxxx "sudo -u mysql du -sh /mysqlback/*"; ssh aaaaaaaaa029xxxxxx "sudo -u mysql du -sh /mysqlback/*"; ssh aaaaaaaaa028xxxxxx "sudo -u mysql du -sh /mysqlback/*"; ssh aaaaaaaaa027xxxxxx "sudo -u mysql du -sh /mysqlback/*"; ssh aaaaaaaaa026xxxxxx "sudo -u mysql du -sh /mysqlback/*"; ssh aaaaaaaaa025xxxxxx "sudo -u mysql du -sh /mysqlback/*"; ssh aaaaaaaaa024xxxxxx "sudo -u mysql du -sh /mysqlback/*"; ssh aaaaaaaaa023xxxxxx "sudo -u mysql du -sh /mysqlback/*"; ssh aaaaaaaaa022xxxxxx "sudo -u mysql du -sh /mysqlback/*"; ssh aaaaaaaaa021xxxxxx "sudo -u mysql du -sh /mysqlback/*"; ssh aaaaaaaaa020xxxxxx "sudo -u mysql du -sh /mysqlback/*"; ssh aaaaaaaaa019xxxxxx "sudo -u mysql du -sh /mysqlback/*"; ssh aaaaaaaaa018xxxxxx "sudo -u mysql du -sh /mysqlback/*"; ssh aaaaaaaaa017xxxxxx "sudo -u mysql du -sh /mysqlback/*"; ssh aaaaaaaaa016xxxxxx "sudo -u mysql du -sh /mysqlback/*"; ssh aaaaaaaaa015xxxxxx "sudo -u mysql du -sh /mysqlback/*"; ssh aaaaaaaaa014xxxxxx "sudo -u mysql du -sh /mysqlback/*"; ssh aaaaaaaaa013xxxxxx "sudo -u mysql du -sh /mysqlback/*"; ssh aaaaaaaaa012xxxxxx "sudo -u mysql du -sh /mysqlback/*"; ssh aaaaaaaaa011xxxxxx "sudo -u mysql du -sh /mysqlback/*"; ssh aaaaaaaaa010xxxxxx "sudo -u mysql du -sh /mysqlback/*"; ssh aaaaaaaaa009xxxxxx "sudo -u mysql du -sh /mysqlback/*"; ssh aaaaaaaaa008xxxxxx "sudo -u mysql du -sh /mysqlback/*"; ssh aaaaaaaaa007xxxxxx "sudo -u mysql du -sh /mysqlback/*"; ssh aaaaaaaaa006xxxxxx "sudo -u mysql du -sh /mysqlback/*"; ssh aaaaaaaaa005xxxxxx "sudo -u mysql du -sh /mysqlback/*"; ssh aaaaaaaaa004xxxxxx "sudo -u mysql du -sh /mysqlback/*"; ssh aaaaaaaaa003xxxxxx "sudo -u mysql du -sh /mysqlback/*"; ssh aaaaaaaaa002xxxxxx "sudo -u mysql du -sh /mysqlback/*"; ssh aaaaaaaaa001xxxxxx "sudo -u mysql du -sh /mysqlback/*"; PS: 1 ssh aaaaaaaaa001xxxxxx "sudo -u mysql du -sh /mysqlback/*";這個指示最後check檢查備份有沒有被刪除的腳本你可以將du -sh /mysqlback/*";換成rm -rf就變成了自己要清理文件的功能了。 2 我這裡ssh是不帶密碼的,如果你的ssh還要帶輸入密碼驗證的話,請試下:ssh pass -p 'password' [email protected] "command"命令 run 這個clean腳本, 我這裡ssh 進aaaaaaaaa001xxxxxx 是不需要密碼的,而且因為進去db server還需要切換到mysql帳號,否則不能rm操作mysql用戶組的文件。遠程命令裡面用了sudo -u mysql前綴。