问题原文
原帖链接 · Jason M. · CC BY-SA 4.0
I am using rsync in a bash script to keep files in sync between a few servers and a NAS. One issue I have run into is trying to generate a list of the files that have changed from the during the rsync.
The idea is that when I run rsync, I can output the files that have changed into a text file - more hoping for an array in memory - then before the script exists I can run a chown on only the changed files.
Has anyone found a way to perform such a task?
# specify the source directory
source_directory=/Users/jason/Desktop/source
# specify the destination directory
# DO NOT ADD THE SAME DIRECTORY NAME AS RSYNC WILL CREATE IT FOR YOU
destination_directory=/Users/jason/Desktop/destination
# run the rsync command
rsync -avz $source_directory $destination_directory
# grab the changed items and save to an array or temp file?
# loop through and chown each changed file
for changed_item in "${changed_items[@]}"
do
# chown the file owner and notify the user
chown -R user:usergroup; echo '!! changed the user and group for:' $changed_item
done
社区高分解答
原帖链接 · Cychih · CC BY-SA 4.0
This question is a little bit old, but I think it worth to be added:
-i is a shortcut of --out-format='%i %n%L'
%i represents a cryptic, 11 character output whose format is the string YXcstpoguax; ref man rsync, -itemize-changes.
And %n means the filename, (section log format of man rsyncd.conf); %L comes into play when there are symlinks to update.
P.S. rsync version 3.1.0
摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。
