簡體   English   中英

Unix腳本,用於將文件(在特定時間段內)從一台服務器復制到另一台服務器

[英]Unix script to copy files (which came in a particular duration) from one server to another server

我需要保護從一台源服務器到目標服務器的復制文件(僅.csv)的安全性(屬於2016年5月和2016年6月)(即,在2016年5月1日至6月30日之間進行的最后修改)。

源服務器10.87.87.89 -> 10.87.87.89源文件夾-> /home/server/source

目標服務器是-> 10.34.69.32目標文件夾-> /home/ftp/destination

TARGET的示例用戶名:a_ftp TARGET的示例用戶名:a_ftp

我已經嘗試了以下命令-

scp /home/server/source/h.xml a_ftp@10.34.69.32://home/ftp/destination

但並非用於獲取所有文件。

首先,您將需要在服務器的文件系統中創建兩個參考文件:

$ ssh server@10.87.87.89 touch --date "2016-05-01" /tmp/start.tmp
$ ssh server@10.87.87.89 touch --date "2016-06-30" /tmp/end.tmp

現在,可以只列出在May / 2016和June / 2016中創建的文件:

$ ssh server@10.87.87.89 find /home/server/source -type f -newer /tmp/start.tmp -not -newer /tmp/end.tmp

最后,您可以在for循環中使用scp ,僅在主機之間復制所需的文件:

for i in `ssh server@10.87.87.89 find /home/server/source -type f -newer /tmp/start.tmp -not -newer /tmp/end.tmp`
do
    scp server@10.87.87.89:$i ftp@10.34.69.32:/home/ftp/destination
done

希望能幫助到你!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM