Other rsync question

csptra

Member


Messages: 54

Hi All,

I don't know if this is better under scripting or general. However, I have this scenario:

I want to copy only the last two directories of a path to the destination. Let's say we have the source directory structure (from a backup structure)

Code:
dir.20180601/mnt/path/to/directory/20180531/dir1
dir.20180602/mnt/path/to/directory/20180601/dir1
dir.20180603/mnt/path/to/directory/20180602/dir1
etc
I know if use --relative, I can do something like:

rsync -avH --relative dir.*/mnt/path/to/directory/*/dir1 /destination/

However, is it copying the entire directory path, as it should :)

but I was wondering if its possible to only send/copy the last two parts of the directory structure. I want to end up with the below (on the destination side):

Code:
/destination/20180531/dir1
/destination/20180601/dir1
/destination/20180602/dir1
I hope this makes sense, if I need to clarify. Please let me know. I'm still looking and experimenting myself.
 

k.jacker

Aspiring Daemon

Reaction score: 434
Messages: 738

Why not simply rsync -avH dir.*/mnt/path/to/directory/ /destination/ ?

What else is in your directory that you do not want to sync? Maybe adding --exclude= could be an option, too.
 
OP
OP
csptra

csptra

Member


Messages: 54

Hi k.jacker,

There are a lot of other folders from backups I don't want to copy. I just wanted to pull those folder keeping the parent directory only (and not grand parent etc)
 

debguy

Active Member

Reaction score: 11
Messages: 139

I suggest just trying it with the -n switch to see if your syntax does what you want.

(-n means dry run, do not actually act)
 

pboehmer

Active Member

Reaction score: 30
Messages: 135

I think with your directory structure, you are going to have to script it out so that it will cd to each 2018 source directory, rsync that directory to appropriate destination, and then repeat.
 
Top