溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

Linux服務(wù)器日志備份到本地

發(fā)布時(shí)間:2020-08-01 16:33:48 來(lái)源:網(wǎng)絡(luò) 閱讀:3766 作者:歸來(lái)仍少年 欄目:建站服務(wù)器

1、確定線上服務(wù)器的日志文件名稱和路徑

2、一臺(tái)本地服務(wù)器能連接公網(wǎng),創(chuàng)建一個(gè)日志賬戶,設(shè)置密碼

3、線上服務(wù)器要求:

 a、確定是否已安裝sshpass包

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

  sshpass-1.06-1.el7.x86_64

  如不存在即安裝yum install -y sshpass

 

  b、寫(xiě)腳本傳送

  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-05/mealtime-member-9076-all-$(date -d "yesterday" +%Y-%m-%d).tar.gz  logbak@備份主機(jī)地址:/logbak/124/                    

  #需確認(rèn)/logbak/124目錄已存在

 

  c、確認(rèn)ssh是否能登錄到遠(yuǎn)程服務(wù)器

  [root@iZwz95ywngc71vxzcd5yx4Z ~]# ssh logbak@備份主機(jī)地址:/logbak/124/ 

  The authenticity of host '備份主機(jī)地址 (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                 #確認(rèn)yes

  Warning: Permanently added '備份主機(jī)地址,xxx.xxx.xxx.xxx' (ECDSA) to the list of known hosts.

  logbak@備份主機(jī)地址's password:                                         #輸入登錄用戶的密碼即可登錄至本地服務(wù)器上

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

  -bash-4.2$

     

4、設(shè)置crontab定時(shí)任務(wù),執(zhí)行傳送日志到本地的腳本

   [root@iZwz9ghdadtaey1msor7gnZ ~]# crontab -l

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


向AI問(wèn)一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI