更新超过 1 周的 rsync 文件

mm1*_*mm1 29 linux rsync

我想在服务器 A 上运行 rsync 以在更新超过 7 天时从服务器 B 复制所有文件。

find . -mtime -7
Run Code Online (Sandbox Code Playgroud)

我不想删除服务器 B 上的文件。

seh*_*ehe 36

这应该让你以一种坚实的方式进行

rsync -RDa0P \
    --files-from=<(find sourcedir/./ -mtime -7 -print0) \
    . user@B:targetdir/
Run Code Online (Sandbox Code Playgroud)

这会复制设备节点、权限、时间戳。我很确定 -H 选项对 --files-from 不准确

  • 要将其设置为远程过滤器:`rsync -avn --files-from=&lt;(ssh user@A 'find /path/on/A/ -mtime -7 -type f -exec basename {} \;') user @A:/path/on/A/ user@B:targetdir` (27认同)

小智 6

我根据cybertoast的注释编写了这个脚本,以便从远程服务器同步到本地。

你可以调用脚本./script.sh 3./script.sh 3 dry一个预演。

#!/bin/bash
TIME=$1
DRYRUN=$2

if [[ -z $TIME ]]; then
  echo "Error: no time argument."
  echo "Please enter the number of days to sync."
  exit 1
fi

if [[ $DRYRUN = "dry" ]]; then
  DRYRUNCMD="--dry-run"
  echo "Dry run initiated..."
fi

rsync -avz $DRYRUNCMD --files-from=<(ssh \
    user@remote "find path/to/data/ \
    -mtime -$TIME ! -name *.mkv -type f \
    -exec ls $(basename {}) \;") \
  user@remote:. .
Run Code Online (Sandbox Code Playgroud)