简体   繁体   中英

SCP to transfer files from remote server which are modified after specific time

In remote server log files are rotated as shown below when the size of the active log file (file.log) is reached 100mb

delete file.log.4
file.log.3 -> file.log.4
file.log.2 -> file.log.3
file.log.1 -> file.log.2
file.log   -> file.log.1

Initially all the files will be moved to local server and renamed as below

file.log_timestamp_of_log4
file.log_timestamp_of_log3
file.log_timestamp_of_log2
file.log_timestamp_of_log1

Then after only those files which are modified after the last script run time should be moved to local server. for example next time when the script runs if file.log.1 and file.log.2 has modification time greater than the previous script rum time then only these should be moved to local server.

Can this be done using scp ?

scp is command to copy from one server to other. So if you are copying from remote to local yes you can use scp . To fetch previous modified date you can use date -r . You can save last script run time to compare. You need to use scp -p to preserve modifed date. To calculate size you can use du -h So do something like following algo

scp -p remotepath:/filename localpath

last_mod = date -r filename

size = du -h filename

if last_mod > script_runtime
{ if size > 100 MB 
 { mv filename > filename1 }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM