大网数据广告活动
服务器运维问答

How to rsync files / folders from a specific date forward?

· 52CE 我爱测

I would like to rsync folders from a specific date and forward. for example. I want to rsync my folders that were created from 3 days ago (and of course 2 days ago, one day ago etc.). I know I need to use find and rsync but I'm n…

问题原文

原帖链接 · edotan · CC BY-SA 3.0

I would like to rsync folders from a specific date and forward. for example. I want to rsync my folders that were created from 3 days ago (and of course 2 days ago, one day ago etc.). I know I need to use find and rsync but I'm not sure how. any idea? Thanks! Dotan.

社区高分解答

原帖链接 · capitalg · CC BY-SA 4.0

Modifying the answer from Thomas which syncs based on the modifiction date of a file to a script, to be more human readeable and sync nested folders as well.

#!/bin/bash

TARGET=/PATH/TO/TARGET
HOST=username@host
SOURCE=/ABSOLUTE/SOURCE/PATH/ON/HOST

touch $TARGET/last_sync

rsync \
    -ahrv \
    --update \
    --files-from=<(ssh $HOST "find $SOURCE -type f -newer $SOURCE/last_sync -exec realpath --relative-to=$SOURCE '{}' \;") \
    $HOST:$SOURCE \
    $TARGET

rsync -ahv $TARGET/last_sync $HOST:$SOURCE

For init one should probably create a last_sync file remotely, to which the following command comes in handy

touch -d "2 hours ago" last_sync

which creates a file called last_sync with a creation date of 2 hours ago.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2013-09-13)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0 / CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。