问题原文
原帖链接 · 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.
摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。
