linux 内网scp 无密码传输

实现多台机器A、B、C无密码自动拷贝机器D上的mysql备份文件:

首先在A\B\C\D机器上生产密钥,运行:

ssh-keygen -t rsa

输入ssh-keygen -t rsa之后全部默认回车,这样就会在/root/.ssh下生成密钥文件

建信任关系:

拷贝A\B\C 的 id_rsa.pub到机器D的authorized_keys文件中

拷贝D 的id_rsa.pub到A\B\C的authorized_keys文件中

或known_hosts文件

[机器D内网IP]:端口 ssh-rsa 机器D的id_rsa.pub

 自动备份及传输脚本

#!/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 [email protected]:$dir

  

你可能感兴趣的:(linux 内网scp 无密码传输)