If the number of directories to backup is not too big, you can put them into the command line using a bash shellscript. The following shellscript is a demo.
Directory structure
$ tree data
data
└── sub1
├── sub1_1
│ ├── a
│ ├── b
│ └── backup
├── sub1_2
│ └── c
└── sub1_3
├── backup
└── d
4 directories, 6 files
Shellscript rsyncer
#!/bin/bash
echo -n 'rsync -avn ' > command
find . -name 'backup' -type f | sed -e 's%/backup%%' -e 's%.*%"&"%' | tr '\n' ' ' >> command
echo ' target/' >> command
bash command
Dry run
$ ./rsyncer
sending incremental file list
created directory target
sub1_1/
sub1_1/a
sub1_1/b
sub1_1/backup
sub1_3/
sub1_3/backup
sub1_3/d
sent 199 bytes received 64 bytes 526.00 bytes/sec
total size is 0 speedup is 0.00 (DRY RUN)
Please notice that sub1/sub1_2 and the file c are not listed.
Backup
Remove the option n
from rsync in the shellscript and run it or from the file command
and run it,
sed 's/-avn/-av/' command > buper
$ bash buper
sending incremental file list
created directory target
sub1_1/
sub1_1/a
sub1_1/b
sub1_1/backup
sub1_3/
sub1_3/backup
sub1_3/d
sent 383 bytes received 148 bytes 1,062.00 bytes/sec
total size is 0 speedup is 0.00
$ tree target
target
├── sub1_1
│ ├── a
│ ├── b
│ └── backup
└── sub1_3
├── backup
└── d
2 directories, 5 files
Please notice that sub1/sub1_2 and the file c are not listed.
ControlPersist
). That way it doesn't matter if you invoke rsync multiple times: they'll reuse the existing SSH connection. – Gilles 'SO- stop being evil' Oct 29 '21 at 16:37