1. Determine the log file name and path of the online server
2, a local server can connect the public network, create a log account, set the password
3, the online server requirements:
A. Determine if the Sshpass package is installed
[Email protected] sh]# Rpm-qa|grep Sshpass
Sshpass-1.06-1.el7.x86_64
Install Yum install-y if not present Sshpass
b, Write script transfer
Such as:
[email protected] ~]# 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 huagzl1! scp/opt/soft/spring-cloud/member-9076-weixin/logs/2017-05/mealtime-member-9076-all-$ (date-d "Yesterday" +%Y-%m-% d). tar.gz [Email protected]:/logbak/124/
#需确认/logbak/124 directory already exists
c. Verify that SSH is able to log on to the remote server
[[email protected] ~]# ssh [email protected]
The authenticity of host ' fwally.eicp.net (175.0.222.186) ' can ' t be established.
ECDSA key fingerprint is d1:9e:2e:3f:50:cf:58:3c:fc:49:6d:13:e2:c4:03:95.
Is you sure want to continue connecting (yes/no)? Yes #确认yes
warning:permanently added ' fwally.eicp.net,175.0.222.186 ' (ECDSA) to the list of known hosts.
[email protected] ' s password: #输入登录用户的密码即可登录至本地服务器上
Last Login:fri-12:56:08 from 192.168.3.10
-bash-4.2$
4, Set crontab Timer task, execute transfer log to local script
[Email protected] ~]# crontab-l
8 * * */bin/bash/root/logbak.sh
Linux server log Backup to local