|
测试环境:redhat linux AS4,SSH,mysql4
测试任务:备份*.*.*.131(以下简称131)上的数据库(iwbt)到*.*.*.162(以下简称162)上。
/*******************************
* I am pefocus,pefocus is me !*
*******************************/
1. 设置无需密码的ssh登陆.在131上生成钥匙对,执行以下命令:
ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa): /root/.ssh/id_rsa
Enter passphrase (empty for no passphrase): 直接回车
Enter same passphrase again: 直接回车
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
96:12:82:26:cb:ec:08:3d:5a:21:60:e1:10:0f:1e:12 root@music.swau.edu.cn
这样,在/root/.ssh/路径下会生成id_rsa,和id_rsa.pub,其中id_rsa是密钥,id_rsa.pub是公钥。
2.把在131上生成的id_rsa.pub拷贝到162上:
scp /root/.ssh/id_rsa.pub root@*.*.*.162:/root/.ssh/login_keys
chmod 400 /root/.ssh/login_keys
3.编写shell脚本
vi /shell/db_bak.sh
#!/bin/bash
#备份数据库
filename=`date +%Y%m%d%H%M%S`
cd /data/mysql-standard-4.1.13-pc-linux-gnu-i686/data
tar cvf /databak/iwbt$filename.tar ./iwbt
scp /databak/iwbt$filename.tar root@*.*.*.162:/databak/iwbt$filename.tar
rm -r /databak/iwbt$filename.tar
保存shell脚本后,运行chmod +x /shell/db_bak.sh
4.运行:crontab -e
5.输入
00 5 * * * root /shell/db_bak.sh
/*******************************
* I am pefocus,pefocus is me !*
*******************************/ |
|