Rsync Help

Forum rules
Before you post please read how to get help
Post Reply
OhioYJ
Level 1
Level 1
Posts: 7
Joined: Sun Jul 01, 2012 3:14 pm

Rsync Help

Post by OhioYJ » Sun Oct 28, 2018 8:18 am

I use the following the command in Windows to make to drives identical, it deletes any extra files / directories, etc from the backup drive.

robocopy source target /E /PURGE

I'm really not in Windows much other than for Steam, so I'd like to recreate this script in Linux. I just need the files on the second drive to end up identical. (It will actually end up being many other drives)

rsync -r -p -t --executability --delete source target

User avatar
WharfRat
Level 20
Level 20
Posts: 11715
Joined: Thu Apr 07, 2011 8:15 pm

Re: Rsync Help

Post by WharfRat » Sun Oct 28, 2018 8:42 am

This is what I use to sync to a backup server rsync -aviuh --progress --delete-after source target
ImageImage

OhioYJ
Level 1
Level 1
Posts: 7
Joined: Sun Jul 01, 2012 3:14 pm

Re: Rsync Help

Post by OhioYJ » Sun Oct 28, 2018 9:29 am

WharfRat wrote:
Sun Oct 28, 2018 8:42 am
This is what I use to sync to a backup server rsync -aviuh --progress --delete-after source target
Thanks for your quick I reply. I tried this. Unfortunately it doesn't seem to work. I threw some random files in test folders on the desktop, some different ones, including directories in one, plus a same file and then made changes to one.

Image

After running the command, one folder still has 108 items - 3.5 GB, the other 4 items - 369 kB. I also noted that the terminal says 94 bytes received? Just to make sure I do want this to be only in one direction, the source drive should never be contaminated by the target drive.

Image

Did I miss something?

User avatar
smurphos
Level 8
Level 8
Posts: 2042
Joined: Fri Sep 05, 2014 12:18 am
Location: Britisher...

Re: Rsync Help

Post by smurphos » Sun Oct 28, 2018 9:46 am

You need another forwardslash at the end of both your source and destination paths. I think you'll find you've effectively copied test into test2 with your command as written.

OhioYJ
Level 1
Level 1
Posts: 7
Joined: Sun Jul 01, 2012 3:14 pm

Re: Rsync Help

Post by OhioYJ » Sun Oct 28, 2018 9:59 am

smurphos wrote:
Sun Oct 28, 2018 9:46 am
You need another forwardslash at the end of both your source and destination paths. I think you'll find you've effectively copied test into test2 with your command as written.
Doh! Well that fixed almost everything. Now the only problem is I made changes to one file in the target destination (so it is technically newer) but I would still like it to be overwritten, with the one from the source. The modified file in the target did not get overwritten.

User avatar
WharfRat
Level 20
Level 20
Posts: 11715
Joined: Thu Apr 07, 2011 8:15 pm

Re: Rsync Help

Post by WharfRat » Sun Oct 28, 2018 10:03 am

smurphos wrote:
Sun Oct 28, 2018 9:46 am
You need another forwardslash at the end of both your source and destination paths. I think you'll find you've effectively copied test into test2 with your command as written.
Yes, the source trailing slash avoids creating an additional directory level at the destination.

So use rsync -aviuh --progress --delete-after source/ target

To test what will be done you can add 'n' rsync -naviuh --progress --delete-after source/ target which will not actually sync -just show what will be done.
ImageImage

User avatar
smurphos
Level 8
Level 8
Posts: 2042
Joined: Fri Sep 05, 2014 12:18 am
Location: Britisher...

Re: Rsync Help

Post by smurphos » Sun Oct 28, 2018 10:12 am

Lose the u parameter if you want to delete or overide newer files on the target.

I refer to rsync --help a lot. Like I did just now. :wink:

Post Reply

Return to “Scripts & Bash”