Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Linux server logs are backed up locally

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

1. Determine the log file name and path of the online server

2. A local server can connect to the public network, create a log account, and set a password

3. Online server requirements:

A, determine whether the sshpass package has been installed

[root@iZwz9ghdadtaey1msor7gnZ sh] # rpm-qa | grep sshpass

Sshpass-1.06-1.el7.x86_64

Install yum install-y sshpass if it does not exist

B. Write script transfer

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-05According to MealtimeAfter members: $(date-d "yesterday" +% Y-%m-%d). Tar.gz logbak@ backup host address: / logbak/124/

# confirm that the / logbak/124 directory already exists

C. Confirm whether ssh can log in to the remote server

[root@iZwz95ywngc71vxzcd5yx4Z ~] # ssh logbak@ backup host address: / logbak/124/

The authenticity of host 'backup host address (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 # confirm yes

Warning: Permanently added 'backup host address, xxx.xxx.xxx.xxx' (ECDSA) to the list of known hosts.

Logbak@ backup host address's password: # enter the password of the login user to log in to the local server

Last login: Fri May 12 12:56:08 2017 from 192.168.3.10

-bash-4.2 $

4. Set crontab scheduled tasks and execute scripts that send logs to the local

[root@iZwz9ghdadtaey1msor7gnZ ~] # crontab-l

45 8 * / bin/bash / root/logbak.sh

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report