![如何将最新文件从一台 Unix 服务器传输到另一台 Unix 服务器?](https://linux22.com/image/1342636/%E5%A6%82%E4%BD%95%E5%B0%86%E6%9C%80%E6%96%B0%E6%96%87%E4%BB%B6%E4%BB%8E%E4%B8%80%E5%8F%B0%20Unix%20%E6%9C%8D%E5%8A%A1%E5%99%A8%E4%BC%A0%E8%BE%93%E5%88%B0%E5%8F%A6%E4%B8%80%E5%8F%B0%20Unix%20%E6%9C%8D%E5%8A%A1%E5%99%A8%EF%BC%9F.png)
如何才能将最新的文件从一台 Unix 服务器传输到另一台 Unix 服务器?
我已经通过 SFTP 连接到服务器 2,并尝试应用 for 循环来检查时间戳,但这不起作用:
sftp $SERVER2 << !EOF
cd $Server2_FILE_LOCATION
echo Pwd File location: $pwd
LastUpdatedTS=$(grep "value of TimeStamp is" /root/airtelSnD/BoTreeScript/BotreeLastFileTS.txt | cut -d'=' -f2)
echo 1
for file in mad_*.*
do
CurrentFileTS=$(stat -c %Y $file |awk '{print strftime( "%Y%m%d%H%M%S", $1 )}')
echo 2
echo TS of last updated file is : $LastUpdatedTS
echo value CurrentFileTS is $CurrentFileTS
echo 3
if [[ $CurrentFileTS -gt $LastUpdatedTS ]]
then
echo if......
mget $file $DESTINATION_SERVER
echo value of TimeStamp is=$CurrentFileTS > $LASTFILE_TS
else
echo else...
fi
done
quit
!EOF
答案1
答案2
Rsync(或 Unison)是最好的
另一个解决方案是使用find
find . -name 'mad_*' -newer last_update -exec sftp ... {} \;
touch last_update