(2)
exclusions='*.mp3'
exclusions+='*.mp4'
Restore() { \
source=somewhere/Backup/ ;
echo "source is $source." ;
destination=elsewhere/workingDirectory ;
echo "destination is $destination." ;
rsync \
-anuv --exclude=$exclusions $source $destination ; }
In a realistic case, there are more than two exclusion patterns.
rsync \
--exclude '*.mp3' \
--exclude '*.mp4' \
rsync \
--exclude=$exclusions
overengineered
You could do something
overengineered like defining an array "excludepatterns" for patterns, and then doing something like
rsync \
$(for pattern in ${excludepatterns[@]} ; do
echo -- "--exclude '$pattern'"
done)
Modulo mistakes, of course.
Hypothetical shell usages (1) & (2).
(1)
Restore() { \
source=somewhere/Backup/ ;
destination=elsewhere/workingDirectory ;
rsync \
--exclude '*.mp3' \
--exclude '*.mp4' \
-anuv $source $destination ; }
(2)
exclusions='*.mp3'
exclusions+='*.mp4'
Restore() { \
source=somewhere/Backup/ ;
destination=elsewhere/workingDirectory ;
rsync \
-anuv --exclude=$exclusions $source $destination ; }
Store the exclusions in an ARRAY, not in a string. Then create a
second array which contains the spelled-out --exclude=... options.
From: Greg Wooledge <greg@wooledge.org>
Date: Fri, 6 Dec 2024 18:44:04 -0500
Store the exclusions in an ARRAY, not in a string. Then create a
second array which contains the spelled-out --exclude=... options.
Unfamiliar to me & interesting. What benefits outweigh the additional complexity?
"${exclusions[@]//#/--exclude=}"
In a realistic case, there are more than two exclusion patterns.
Comments or suggestions about the two possibilities? Astonishingly
better ideas? =8~o
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 546 |
Nodes: | 16 (0 / 16) |
Uptime: | 157:02:54 |
Calls: | 10,384 |
Calls today: | 1 |
Files: | 14,056 |
Messages: | 6,416,474 |