实现目标机器A无密码自动拷贝机器B上的mysql备份文件:
首先在AB机器上生产密钥,运行:
ssh-keygen -t rsa
输入ssh-keygen -t rsa之后全部默认回车,这样就会在/root/.ssh下生成密钥文件
建信任关系:
拷贝A的 id_rsa.pub到机器B的authorized_keys文件中
自动备份及传输脚本
#!/bin/bash # This is a ShellScript For Auto DB Backup and Delete old Backup #database name name=t_base dir=/alidata/backup/t_v3/$name/ mkdir -p $dir #backup file time time=_`date +%Y_%m%d_%H%M` #mysql user user=root #mysql password pass=123456 #mysqldump -u$user -h 127.0.0.1 -P 3306 -p$pass --single-transaction $name > $dir$name$time.sql mysqldump -u$user -p$pass --master-data=2 $name > $dir$name$time.sql #Delete data 14 days ago find $dir -name "$name_*.sql" -type f -mtime +14 -exec rm {} ; > /dev/null 2>&1 #copy database cd $dir scp -P 22 $dir$name$time.sql root@192.168.1.130:$dir