1. 华为交换机配置ssh & sftp
# 生成密匙
[Huawei] rsa local-key-pair create
# 配置vty
[Huawei] user-interface vty 0 4
[Huawei-ui-vty0-4] authentication-mode aaa
[Huawei-ui-vty0-4] protocol inbound all (或者仅 ssh)
# 创建ssh用户,配置password认证
[Huawei] ssh user admin
[Huawei] ssh user admin authentication-type all (或者仅用 password)
[Huawei] aaa
[Huawei-aaa] local-user admin password cipher MyPassword
[Huawei-aaa] local-user admin privilege level 15
[Huawei-aaa] local-user admin service-type telnet ssh(或者仅保留 ssh)
[Huawei] ssh user admin service-type all
# 开启stelnet功能
[Huawei] stelnet server enable
[Huawei] ssh server port 43000
[Huawei] sftp server enable
2. 远程备份脚本
主机清单文件 .host.lst
# host port user password filename
192.168.xxx.xxx 43000 admin password@123 vrpcfg.zip
192.168.xxx.xxx 43000 admin password@123 vrpcfg.cfg
备份脚本 configBackup.sh
#!/bin/bash
hostFile=".host.lst"
currentDate=$(date +%Y%m%d)
days=15
function download() {
eval $(echo ${@} | awk '{printf("host=%s; port=%s; user=%s; password=%s; fileName=%s; date=%s", $1, $2, $3, $4, $5, $6)}')
sshpass -p ${password} sftp -P ${port} -o StrictHostKeyChecking=no -o ConnectTimeout=60 ${user}@${host}:/${fileName} ${date}-${host}-${fileName}
}
/usr/bin/cat ${hostFile} | egrep -v '^$|^#' | while read row
do
download ${row} ${currentDate} &
done
/usr/bin/find . -name *.zip -type f -mtime +${days} |xargs rm -rf
/usr/bin/find . -name *.cfg -type f -mtime +${days} |xargs rm -rf
wait
exit 0
定时任务 crontab
0 1 * * * /usr/bin/sh /data/backup/configBackup.sh