码迷,mamicode.com
首页 > 系统相关 > 详细

Linux服务器日志备份到本地

时间:2017-05-12 21:58:34      阅读:303      评论:0      收藏:0      [点我收藏+]

标签:linux   log   

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 huagzl1! scp /opt/soft/spring-cloud/member-9076-weixin/logs/2017-05/mealtime-member-9076-all-$(date -d "yesterday" +%Y-%m-%d).tar.gz  logbak@fwally.eicp.net:/logbak/124/                    

  #需确认/logbak/124目录已存在

 

  c、确认ssh是否能登录到远程服务器

  [root@iZwz95ywngc71vxzcd5yx4Z ~]# ssh logbak@fwally.eicp.net

  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.

  logbak@fwally.eicp.net‘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


Linux服务器日志备份到本地

标签:linux   log   

原文地址:http://shaoniana.blog.51cto.com/11471609/1925112

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!