Linux服务器日志备份到本地
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Linux服务器日志备份到本地相关的知识,希望对你有一定的参考价值。
1、确定线上服务器的日志文件名称和路径
2、一台本地服务器能连接公网,创建一个日志账户,设置密码
3、线上服务器要求:
a、确定是否已安装sshpass包
[[email protected] sh]# rpm -qa|grep sshpass
sshpass-1.06-1.el7.x86_64
如不存在即安装yum install -y sshpass
b、写脚本传送
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目录已存在
c、确认ssh是否能登录到远程服务器
[[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.
Are you sure you 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 May 12 12:56:08 2017 from 192.168.3.10
-bash-4.2$
4、设置crontab定时任务,执行传送日志到本地的脚本
[[email protected] ~]# crontab -l
45 8 * * * /bin/bash /root/logbak.sh
以上是关于Linux服务器日志备份到本地的主要内容,如果未能解决你的问题,请参考以下文章