您好,登錄后才能下訂單哦!
1、確定線上服務器的日志文件名稱和路徑
2、一臺本地服務器能連接公網,創建一個日志賬戶,設置密碼
3、線上服務器要求:
a、確定是否已安裝sshpass包
[root@iZwz9ghdadtaey1msor7gnZ sh]# rpm -qa|grep sshpass
sshpass-1.06-1.el7.x86_64
如不存在即安裝yum install -y sshpass
b、寫腳本傳送
Such as:
[root@iZwz9ghdadtaey1msor7gnZ ~]# cat logbak.sh
#!/bin/bash
cd /opt/soft/spring-cloud/member-9076-weixin/logs/2017-05/
tar zcf mealtime-member-9076-all-$(date -d "yesterday" +%Y-%m-%d).tar.gz mealtime-member-all-$(date -d "yesterday" +%Y-%m-%d)-1.log
sshpass -p passwd scp /opt/soft/spring-cloud/member-9076-weixin/logs/2017-05/mealtime-member-9076-all-$(date -d "yesterday" +%Y-%m-%d).tar.gz logbak@備份主機地址:/logbak/124/
#需確認/logbak/124目錄已存在
c、確認ssh是否能登錄到遠程服務器
[root@iZwz95ywngc71vxzcd5yx4Z ~]# ssh logbak@備份主機地址:/logbak/124/
The authenticity of host '備份主機地址 (xxx.xxx.xxx.xxx)' can't be established.
ECDSA key fingerprint is d1:9e:2e:3f:50:cf:58:3c:fc:49:6d:13:e2:c4:03:95.
Are you sure you want to continue connecting (yes/no)? yes #確認yes
Warning: Permanently added '備份主機地址,xxx.xxx.xxx.xxx' (ECDSA) to the list of known hosts.
logbak@備份主機地址's password: #輸入登錄用戶的密碼即可登錄至本地服務器上
Last login: Fri May 12 12:56:08 2017 from 192.168.3.10
-bash-4.2$
4、設置crontab定時任務,執行傳送日志到本地的腳本
[root@iZwz9ghdadtaey1msor7gnZ ~]# crontab -l
45 8 * * * /bin/bash /root/logbak.sh
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。