Linux server log Backup to local

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.