脚本内容:
[email protected]:Active:Standalone] tmp # more backup1.sh
#!/bin/sh
cd /shared/tmp
date_tag=`date +%Y%m%d%H%M%S`
XXXX save sys ucs /shared/tmp/$HOSTNAME-$date_tag.ucs
sftp [email protected]10.1.1.110 << EOF
-put /shared/tmp/$HOSTNAME-$date_tag.ucs /var/tmp/
!rm /shared/tmp/$HOSTNAME-$date_tag.ucs
bye
EOF
因为sftp走的是22端口,所以运行脚本前要本证ssh可以无密码登录远端机器。
步骤可以参考: https://www.computerhope.com/unix/sftp.htm,
- 在F5上ssh-keygen
- cd ~/.ssh
- 把F5 id_rsa.pub文件里的内容放到远端机器的~/.ssh/authorized_keys里。这样ssh就不需要密码可以登录了。
- 手动执行脚本,验证效果
[[email protected]:Active:Standalone] tmp # bash -x ./backup1.sh
+ cd /shared/tmp
++ date +%Y%m%d%H%M%S
+ date_tag=20170817100114
+ tmsh save sys ucs /shared/tmp/ltm2.f5.com-20170817100114.ucs
Saving active configuration...
/shared/tmp/ltm2.f5.com-20170817100114.ucs is saved.
+ sftp [email protected]10.1.1.110
Connecting to 10.1.1.110...
sftp> -put /shared/tmp/ltm2.f5.com-20170817100114.ucs /var/tmp/
Uploading /shared/tmp/ltm2.f5.com-20170817100114.ucs to /var/tmp/ltm2.f5.com-20170817100114.ucs
/shared/tmp/ltm2.f5.com-20170817100114.ucs 100% 2851KB 2.8MB/s 00:00
sftp> !rm /shared/tmp/ltm2.f5.com-20170817100114.ucs
sftp> bye
[[email protected]:Active:Standalone] tmp #
确保远端备份成功,本地删除成功。