[英]How to copy directory from remote server with scp, excluding a specific subdirectory
[英]SCP to transfer files from remote server which are modified after specific time
在遠程服務器中,當活動日志文件(file.log)的大小達到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
最初,所有文件都將移至本地服務器並按以下方式重命名
file.log_timestamp_of_log4
file.log_timestamp_of_log3
file.log_timestamp_of_log2
file.log_timestamp_of_log1
然后,僅應將在上次腳本運行時間之后已修改的文件移至本地服務器。 例如,下次運行腳本時,如果file.log.1和file.log.2的修改時間大於上一個腳本朗姆時間,那么只有這些修改時間應移至本地服務器。
可以使用scp完成此操作嗎?
scp是從一台服務器復制到另一台服務器的命令。 因此,如果要從遠程復制到本地,可以使用scp 。 要獲取以前的修改日期,可以使用date -r
。 您可以保存上一個腳本運行時間以進行比較。 您需要使用scp -p
保留修改后的日期。 要計算大小,您可以使用du -h
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 }
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.