我正在运行一个命令,将一些文件更新到中央服务器。
该命令首先执行 a--dry-run
以显示将传输哪些文件。
可能会发生服务器上的较新文件可能必须被覆盖的情况 - 我希望该rsync --dry-run
命令在这种情况下具体显示。
目前 rsync 命令看起来像
rsync -aviO sdir/ ddir
假设命令产生输出
>f.st...... file-newer-on-source
>f.st...... file-newer-on-destination
为了清楚起见,执行rsync -aviuO sdir/ ddir
(--update) 通常会产生,
>f.st...... file-newer-on-source
但我希望该命令显示何时要覆盖较新的文件!目前file-newer-on-source
和之间的输出没有区别...-destination
。像这样的东西会很棒
>f.st...... file-newer-on-source
>f.sT...... file-newer-on-destination
但事实并非如此。
是否还有其他选项或out-format
设置可以专门显示较新的文件要被覆盖吗?
答案1
要查看的位置将在-v
(详细)选项中,该选项可以重复。这并没有准确提供所要求的信息。
但是,您可以通过使用其他选项运行不同的部分来构建所需的内容(请参阅联机帮助页):
-u, --update
跳过接收器上较新的文件--existing
跳过在接收器上创建新文件--ignore-existing
跳过更新接收器上存在的文件
-u
这是一个使用and 的示例--existing
:
#!/bin/sh
# $Id: check-rsync,v 1.3 2022/10/11 20:02:24 tom Exp $
# Make a readable report showing whether files would be added (+), deleted (-),
# updated (>) or downdated (<) using rsync between two directories.
#
# Updates to directories are ignored.
#
# author: Thomas E. Dickey (2015)
usage() {
cat >&2 <<-EOF
usage: check-rsync [-d] [source] [target]
EOF
exit 1
}
OPTS=
while [ $# != 0 ]
do
case .$1 in
(.-*)
OPTS="$OPTS $1"
shift 1
;;
(*)
break
;;
esac
done
[ $# = 2 ] || usage
[ -d "$1" ] || usage
[ -d "$2" ] || usage
LANG=C
export LANG
SOURCE=$1
TARGET=$2
MYTEMP=$(mktemp -d)
trap "cd; rm -rf $MYTEMP" EXIT
syncit() {
rsync "$@" -n -vaz --delete $OPTS "$SOURCE"/ "$TARGET" | \
sed -e '/^\(sending\|sent\|total\) /d' \
-e '/^$/d' \
-e '/^\.\//d' \
-e '/\/$/d' | \
sort
}
cd "$MYTEMP" || exit
syncit >all-updates
syncit -u >was-newer
syncit --existing >was-existing
comm -23 all-updates was-existing | \
sed -e '/^deleting /d' \
-e 's/^/+ /' >>report
comm -23 all-updates was-newer | \
sed -e '/^deleting /d' \
-e 's/^/< /' >>report
sed -e 's/^deleting /- /' -e t -e d all-updates >>report
comm -12 all-updates was-newer | \
sed -e 's/^[[:space:]]\+//' \
-e '/^deleting /d' -e 's/^/> /' >>report
sort -k2 report
我用它来比较两个本地目录树(大约 10,000 个文件,大约有 100 个更改)。该脚本明确检查其参数是否为目录。该检查将被修改以用于远程系统,但由于问题涉及如何使用rsync
选项,而不是基本的 shell 脚本,因此该更改不是本示例的一部分。
如果将脚本扩展为 show = 以显示未更改的文件,则第三个选项将很有用。但我对此没有实际用途:将其作为读者的练习。
示例输出:
+ anon_ftp/pub/xterm/current/xterm-374.tgz
> anon_ftp/pub/xterm/current/xterm-374.tgz
+ anon_ftp/pub/xterm/current/xterm-374.tgz.asc
> anon_ftp/pub/xterm/current/xterm-374.tgz.asc
> anon_ftp/pub/xterm/current/xterm.tar.gz -> xterm-374.tgz
+ anon_ftp/pub/xterm/patches/xterm-374.patch.gz
> anon_ftp/pub/xterm/patches/xterm-374.patch.gz
+ anon_ftp/pub/xterm/patches/xterm-374.patch.gz.asc
> anon_ftp/pub/xterm/patches/xterm-374.patch.gz.asc
+ anon_ftp/pub/xterm/xterm-374.tgz
> anon_ftp/pub/xterm/xterm-374.tgz
+ anon_ftp/pub/xterm/xterm-374.tgz.asc
> anon_ftp/pub/xterm/xterm-374.tgz.asc
> anon_ftp/pub/xterm/xterm.tar.gz -> xterm-374.tgz
+ httpdocs/archives/xterm/current/xterm-374.tgz
> httpdocs/archives/xterm/current/xterm-374.tgz
+ httpdocs/archives/xterm/current/xterm-374.tgz.asc
> httpdocs/archives/xterm/current/xterm-374.tgz.asc
> httpdocs/archives/xterm/current/xterm.tar.gz -> xterm-374.tgz
+ httpdocs/archives/xterm/patches/xterm-374.patch.gz
> httpdocs/archives/xterm/patches/xterm-374.patch.gz
+ httpdocs/archives/xterm/patches/xterm-374.patch.gz.asc
> httpdocs/archives/xterm/patches/xterm-374.patch.gz.asc
+ httpdocs/archives/xterm/xterm-374.tgz
> httpdocs/archives/xterm/xterm-374.tgz
+ httpdocs/archives/xterm/xterm-374.tgz.asc
> httpdocs/archives/xterm/xterm-374.tgz.asc
> httpdocs/archives/xterm/xterm.tar.gz -> xterm-374.tgz
> httpdocs/datafiles/current/xterm.tar.gz
> httpdocs/datafiles/release/xterm.tar.gz
> httpdocs/xterm/ctlseqs/ctlseqs-contents.html
> httpdocs/xterm/ctlseqs/ctlseqs.html
> httpdocs/xterm/ctlseqs/ctlseqs.pdf
> httpdocs/xterm/ctlseqs/ctlseqs.ps
> httpdocs/xterm/ctlseqs/ctlseqs.txt
> httpdocs/xterm/manpage/koi8rxterm.html
> httpdocs/xterm/manpage/koi8rxterm.pdf
> httpdocs/xterm/manpage/koi8rxterm.ps
> httpdocs/xterm/manpage/koi8rxterm.txt
> httpdocs/xterm/manpage/resize.html
> httpdocs/xterm/manpage/resize.pdf
> httpdocs/xterm/manpage/resize.ps
> httpdocs/xterm/manpage/resize.txt
> httpdocs/xterm/manpage/uxterm.html
> httpdocs/xterm/manpage/uxterm.pdf
> httpdocs/xterm/manpage/uxterm.ps
> httpdocs/xterm/manpage/uxterm.txt
> httpdocs/xterm/manpage/xterm-contents.html
> httpdocs/xterm/manpage/xterm.html
> httpdocs/xterm/manpage/xterm.pdf
> httpdocs/xterm/manpage/xterm.ps
> httpdocs/xterm/manpage/xterm.txt
> httpdocs/xterm/terminfo-contents.html
> httpdocs/xterm/terminfo-entries.html
> httpdocs/xterm/terminfo-header.html
> httpdocs/xterm/terminfo.html
> httpdocs/xterm/xterm.log.html
> logs/access_log
> logs/access_log.processed
> logs/access_log.webstat
> logs/access_ssl_log
> logs/access_ssl_log.processed
> logs/access_ssl_log.webstat
> logs/error_log
> logs/lynx.invisible-island.net/access_log
> logs/lynx.invisible-island.net/access_log.processed
> logs/lynx.invisible-island.net/access_log.webstat
> logs/lynx.invisible-island.net/access_ssl_log
> logs/lynx.invisible-island.net/access_ssl_log.processed
> logs/lynx.invisible-island.net/access_ssl_log.processed.1.gz
> logs/lynx.invisible-island.net/access_ssl_log.processed.2.gz
> logs/lynx.invisible-island.net/access_ssl_log.processed.3.gz
> logs/lynx.invisible-island.net/access_ssl_log.processed.4.gz
> logs/lynx.invisible-island.net/access_ssl_log.processed.5.gz
> logs/lynx.invisible-island.net/access_ssl_log.webstat
> logs/lynx.invisible-island.net/error_log
> logs/lynx.invisible-island.net/proxy_access_ssl_log
> logs/proxy_access_log
> logs/proxy_access_ssl_log
> logs/proxy_error_log
> logs/xferlog
> logs/xferlog.processed
> logs/xferlog.webstat