Question

I had the source directory :

root/sourceDir1/sourceDir11
root/sourceDir1/sourceDir12
root/sourceDir1/sourceDir13
root/sourceDir1/sourceDir14
root/sourceDir2/SourceDir21
root/sourceDir2/SourceDir22
root/sourceDir2/SourceDir23
root/sourceDir2/SourceDir24
root/sourceDir2/SourceDir25
root/sourceDir2/SourceDir26

How can I use rsync command to sync these directories as specified in below:

rootTarget1/sourceDir11
rootTarget1/sourceDir12
rootTarget1/sourceDir13
rootTarget1/sourceDir14

rootTarget2/sourceDir21
rootTarget2/sourceDir22
rootTarget2/sourceDir23
rootTarget2/sourceDir24
rootTarget2/sourceDir25
rootTarget2/sourceDir26

Basically I would like to split the source directories into 2 sets, one set of dirs should sync to rootTarget1 and another set should sync to rootTarget2

Was it helpful?

Solution

try this script:

#!/bin/bash
for ((x=1;x<=2;x++));
do if [ x = 1 ] ;
    then for ((y=1;y<=4;y++)); 
             do rsync root/sourceDir${x}/SourceDir${x}${y} rootTarget${x}/Sourcedir${x}${y}" ;
         done ;
   else for ((y=1;y<=6;y++)) ; 
             do rsync root/sourceDir${x}/SourceDir${x}${y} rootTarget${x}/SourceDir${x}${y}" ;
         done ;
   fi;
done
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top