rsync won't sync; need help with rsync options / code

About writing shell scripts and making the most of your shell
Forum rules
Topics in this forum are automatically closed 6 months after creation.
Locked
User avatar
linx255
Level 5
Level 5
Posts: 668
Joined: Mon Mar 17, 2014 12:43 am

rsync won't sync; need help with rsync options / code

Post by linx255 »

I want to sync /$dir1/$dir2/$dir3/* to /, meaning I want whatever is in $dir3 to be copied to /.

My command is:

Code: Select all

sudo rsync --temp-dir=/tmp --progress -rgvclspotR /folder/folder/file /
But it doesn't do anything. Nothing is copied anywhere. If I remove the R, it puts all the * files in / but does not re-create the directory structures.

I don't understand. Help? I tried -a to no avail.

Also, this is intended to reproduce my OS on another partition. Do I need a -H or not? I want the hard links to remain but not share inodes with those on the source partition.

Thanks
Last edited by LockBot on Wed Dec 28, 2022 7:16 am, edited 2 times in total.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
- I'm running Mint 18 Mate 64-bit
- 4.15.0-34-generic x86_64
- All my bash scripts begin with #!/bin/bash
UltramaticOrange

Re: rsync won't sync; need help with rsync options / code

Post by UltramaticOrange »

include -a and I think you'll be good.
User avatar
linx255
Level 5
Level 5
Posts: 668
Joined: Mon Mar 17, 2014 12:43 am

Re: rsync won't sync; need help with rsync options / code

Post by linx255 »

No, adding -a doesn't solve it.

It's weird; seems I remember this code working before.

I had removed the -a for some reason I don't recall, but either way it will not sync.

My code is now -avcsX .
- I'm running Mint 18 Mate 64-bit
- 4.15.0-34-generic x86_64
- All my bash scripts begin with #!/bin/bash
User avatar
Flemur
Level 20
Level 20
Posts: 10097
Joined: Mon Aug 20, 2012 9:41 pm
Location: Potemkin Village

Re: rsync won't sync; need help with rsync options / code

Post by Flemur »

This was generated by grsync; I use it to backup a Mint OS while it's running. Restore tested and works.

Code: Select all

rsync -r -t -p -o -g -x -v --progress --delete -l -H -i -s --exclude=.Trash-1000 --exclude=lost+found --modify-window=1 --exclude={/dev/*,/proc/*,/sys/*,/tmp/*,/run/*,/media/*,/lost+found} / /mnt/LBAK/MINT/

Edit:
I want to sync /$dir1/$dir2/$dir3/* to /, meaning I want whatever is in $dir3 to be copied to /.

You can do that with "cp -ax /$dir1/$dir2/$dir3/* /."
Please edit your original post title to include [SOLVED] if/when it is solved!
Your data and OS are backed up....right?
User avatar
linx255
Level 5
Level 5
Posts: 668
Joined: Mon Mar 17, 2014 12:43 am

Re: rsync won't sync; need help with rsync options / code

Post by linx255 »

meaning I want whatever is in $dir3 to be copied to /.
My bad, I mean, not copied, but synced. And allow me to clarify further.

Let's say I have a copy of my system files in /$dir1/$dir2/$dir3/ .
They can be anything; i.e. /etc/fstab ==> /$dir1/$dir2/$dir3/etc/fstab.
But I am syncing more than one system file and from multiple directories.
Therefore I want to sync /$dir1/$dir2/$dir3/* to /, meaning that /$dir1/$dir2/$dir3/etc/fstab gets synced to /etc/fstab, /$dir1/$dir2/$dir3/home/mint/.config gets synced to /home/mint/.config, etc. I.e. /$dir1/$dir2/$dir3/ is the root directory containing the root directories of all the system files I'm syncing.

sudo rsync -rtpogxvlHis --progress --delete --exclude=.Trash-1000 --exclude=lost+found --modify-window=1 --exclude={/dev/*,/proc/*,/sys/*,/tmp/*,/run/*,/media/*,/lost+found} /dir1/dir2/dir3/* /

syncs everything in dir3 to / without placing them in the correct directories. Everything goes into root and makes a huge mess.

sudo rsync -rtpogxvlHisR --progress --delete --exclude=.Trash-1000 --exclude=lost+found --modify-window=1 --exclude={/dev/*,/proc/*,/sys/*,/tmp/*,/run/*,/media/*,/lost+found} /dir1/dir2/dir3/* /

does nothing that I can tell. ( R for relative ) It does not sync anything, or perhaps syncs the source to itself.

Do I have to make each item in the list to be synced a variable which gets placed after /$dir/$dir2/$dir/ and after the / ?

I suppose I need a way to tell rsync the destination for each item, say, using a loop, huh?
I suppose I can't just specify a wildcard and expect it to know where to put them.

I hope I'm making sense.
- I'm running Mint 18 Mate 64-bit
- 4.15.0-34-generic x86_64
- All my bash scripts begin with #!/bin/bash
User avatar
Flemur
Level 20
Level 20
Posts: 10097
Joined: Mon Aug 20, 2012 9:41 pm
Location: Potemkin Village

Re: rsync won't sync; need help with rsync options / code

Post by Flemur »

syncs everything in dir3 to / without placing them in the correct directories. Everything goes into root and makes a huge mess.

So rather than getting /home/username/.config/... you get /home and /username and /.config and /every-other-file ?
Is /dir1 on the same partition as "/" ?

I'm no expert on rsync - that's why I use grsync, with its boxes to check(!)...perhaps try that - or take a look at
https://wiki.archlinux.org/index.php/Fu ... with_rsync
http://www.mikerubel.org/computers/rsyn ... #Isolation
Please edit your original post title to include [SOLVED] if/when it is solved!
Your data and OS are backed up....right?
User avatar
linx255
Level 5
Level 5
Posts: 668
Joined: Mon Mar 17, 2014 12:43 am

Re: rsync won't sync; need help with rsync options / code

Post by linx255 »

Hm, well, looks like rsync / grsync doesn't understand what I want to do. Apparently, I have to use variable substitutes for source and destination otherwise it copies the entire /$dir1/$dir2/$dir3 and not just the * following $dir3. Apparently, there's no way to tell it "don't transfer the /$dir1/$dir/$dir3 base structure". I was hoping for some way to do this without variable substitutes but I suppose it doesn't really matter if I must.
- I'm running Mint 18 Mate 64-bit
- 4.15.0-34-generic x86_64
- All my bash scripts begin with #!/bin/bash
BlackVeils

Re: rsync won't sync; need help with rsync options / code

Post by BlackVeils »

you dont need to use the /path/to/folder/* methods in rsync to copy contents, maybe thats the problem? mine works with just the trailing slash /path/to/folder/
mitchellk

Re: rsync won't sync; need help with rsync options / code

Post by mitchellk »

This structure of rsync works perfect for me. Always be sure to first test it with --dry-run to see what output it creates

rsync -av --include="*/" --include="*" --exclude="*" SOURCEFOLDER/ DESTINATIONFOLDER/ --dry-run

Hope that works for you and if it produces an output that is correct simply remove --dry-run and run it again
User avatar
linx255
Level 5
Level 5
Posts: 668
Joined: Mon Mar 17, 2014 12:43 am

Re: rsync won't sync; need help with rsync options / code

Post by linx255 »

Thanks for the replies; I'll have to get back with you another time.
Cheers!
- I'm running Mint 18 Mate 64-bit
- 4.15.0-34-generic x86_64
- All my bash scripts begin with #!/bin/bash
Locked

Return to “Scripts & Bash”