i like rsync my photos from one (linux) disc partition to an other (backup location) using an shell script. The problem is, that I need to re-scale all photos which are saved on the backup location, for example with mogrify
.
我喜欢使用shell脚本将我的照片从一个(linux)磁盘分区复制到另一个(备份位置)。问题是,我需要重新缩放保存在备份位置的所有照片,例如mogrify。
Is it possible to post-process every file, which is synced/copied by rsync? In oder to execute mogrify
on every synced file?
是否可以对rsync同步/复制的每个文件进行后处理?在oder中对每个同步文件执行mogrify ?
An other way could using rsync (only) to generate the list of files which have to be synced. Next step: run a loop to mogrify
every list entry in order to output the scaled photo to the backup location.
另一种方法可以使用rsync(仅)生成必须同步的文件列表。下一步:运行一个循环来固定每个列表条目,以便将缩放的照片输出到备份位置。
The problem is, that I have to add all the directories and child-directories to keep the original folder structure before saving the photo.
问题是,在保存照片之前,我必须添加所有目录和子目录以保留原始文件夹结构。
Using rsync would handle the folder creation "on the fly".
使用rsync可以动态创建文件夹。
So: is it possible to execute an command on every file synced with rsync?
那么:是否可以对每个与rsync同步的文件执行命令?
1 个解决方案
#1
3
rsync
has a -i
/--itemize-changes
flag to output a resume of what it does with each file.
rsync有一个-i/- itemize-changes标志来输出它对每个文件所做的操作。
I suggest you to play a bit with it, I'm seeing it outputs lines like >f+++++++++ file1
for a new file, >f..T...... file1
for an unchanged file, >f.sT...... file1
for an update, etc...
我建议您使用它,我看到它输出的是像>,f++++++++的文件,一个新的文件,>。文件1,未修改的文件,>f.sT…文件1更新,等等…
Having that, you can read this output into a variable, and parse this with grep
and cut
:
有了它,您就可以将这个输出读入一个变量,然后使用grep和cut解析它:
#!/bin/bash
log=$(rsync -i rsync-client/* rsync-server/)
newFiles=$(echo "$log" | grep '>f+++++++++' | cut -d' ' -f2)
for file in $newFiles
do
echo "Added file $file"
done
#1
3
rsync
has a -i
/--itemize-changes
flag to output a resume of what it does with each file.
rsync有一个-i/- itemize-changes标志来输出它对每个文件所做的操作。
I suggest you to play a bit with it, I'm seeing it outputs lines like >f+++++++++ file1
for a new file, >f..T...... file1
for an unchanged file, >f.sT...... file1
for an update, etc...
我建议您使用它,我看到它输出的是像>,f++++++++的文件,一个新的文件,>。文件1,未修改的文件,>f.sT…文件1更新,等等…
Having that, you can read this output into a variable, and parse this with grep
and cut
:
有了它,您就可以将这个输出读入一个变量,然后使用grep和cut解析它:
#!/bin/bash
log=$(rsync -i rsync-client/* rsync-server/)
newFiles=$(echo "$log" | grep '>f+++++++++' | cut -d' ' -f2)
for file in $newFiles
do
echo "Added file $file"
done