简体   繁体   English

来自昨天的scp文件

[英]scp files from yesterday

I want to copy files from a remote Server to a local server. 我想将文件从远程服务器复制到本地服务器。 The problem is: I only want to copy the files from yesterday. 问题是:我只想复制昨天的文件。 The remote server is writing logfiles and at 23:59 the logrotation is compressing it to a file [name]_[date].log.gz. 远程服务器正在写日志文件,在23:59,logrotation将其压缩为文件[name] _ [date] .log.gz。 At 6:00 in the morning a cronjob on the local server needs to copy the file previously created from the remote server. 早上6点,本地服务器上的cronjob需要复制先前从远程服务器创建的文件。 Does anyone know how to do this? 有谁知道如何做到这一点?

Regards, Alex 问候,亚历克斯

You can use a script like this 你可以使用这样的脚本

for i in `find /interface/outbound/Web -type f -ctime -1`
do
scp $i user@$destination_server:/destination_directory/
done

in particular the command find as the following features for example: 特别是该命令可以找到以下功能,例如:

find . -ctime -1 # which are created less than 1 day ago from currrent folder.
find . -ctime +2 # finds files which are created older than 2 days from currrent folder.

where ctime is the creation time. 其中ctime是创建时间。 It's also possible to use the modification time mtime in this way: 也可以这样使用修改时间mtime

find . -mtime 0   # find files modified between now and 1 day ago
find . -mtime -1  # find files modified less than 1 day ago
find . -mtime 1   # find files modified between 24 and 48 hours ago
find . -mtime +1  # find files modified more than 48 hours ago

More information in man find 更多关于男人的信息

Edit: 编辑:

To have the same behaviour from remote to local you can use something like: 要从远程到本地具有相同的行为,您可以使用以下内容:

latest_file=`ssh user@destination_server find /pathtoDir -type f -ctime -1`
/usr/bin/scp user@destination_server:$latest_file /local_dir 
echo SCP Completed.

At this moment I haven't a Unix environment to make some tests. 此刻我还没有Unix环境来进行一些测试。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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