Linux for automatic remote backup (SCP+SSH)

Source: Internet
Author: User
Tags scp command

The server that is just on-line needs to back up the log, to back up to another server, in order to reduce the workload, the use of Linux scheduled tasks to automatically execute. Because the server is Linux, the remote replication SCP command for Linux is used. But here is a problem, that is, the SCP command to enter the password, the online probably collected two ways: ① is the use of the Except method (will store the plaintext password), ② using SSH to generate the key. Here I take the second way.

Backup method: Copy the previous day's log file to the backup server, then compress and delete the copied local files. Log files are generated every day and are formatted with access_20151214 similar file names.

#首先用变量保存前一天的日期:

ngnix_day=$ (date-d last-day +%y%m%d)

Then back up the file

SCP [Email protected]:/logdata/access_$ngnix_day.log/logdata/nginxlog/

(SCP ... Source File Destination Path)

Compress the copied log files before deleting the source files (--remove-files)

Tar-czf access_$ngnix_day.tar.gz Access_$ngnix_day.log--remove-files

The backup operation has been completed here

Here is the implementation of SCP without password login

1. Run ssh-keygen-t RSA on A to generate Id_rsa and id_rsa.pub two files under/root/.ssh
Copy backup under/root/.ssh id_rsa.pub named ID_RSA.PUB.A

2. Also run ssh-keygen-t RSA on B

3, under the/root/.ssh of B to create a Authorized_keys file to the Id_rsa.pub.a file in A b/root/.ssh
Write ID_RSA.PUB.A to the Authorized_keys file with the cat command

SCP./ID_RSA.PUB.A B's Ip:/root/.ssh
Cat ID_RSA.PUB.A >> Authorized_keys

Test: Eventually copy files from B server to a, you don't need to enter a password

In the process of generating the key, always enter, or you need to enter the password of the setting

=============================================================

Problem:

When the first implementation of the SCP will appear warning, this time to enter "Yes".

Related question Description http://www.myexception.cn/operating-system/1616889.html

  

Linux for automatic remote backup (SCP+SSH)

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.