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)