Rsync Help

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
OhioYJ
Level 1
Level 1
Posts: 36
Joined: Sun Jul 01, 2012 3:14 pm

Rsync Help

Post by OhioYJ »

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
Last edited by LockBot on Wed Dec 28, 2022 7:16 am, edited 1 time in total.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
WharfRat

Re: Rsync Help

Post by WharfRat »

This is what I use to sync to a backup server rsync -aviuh --progress --delete-after source target
OhioYJ
Level 1
Level 1
Posts: 36
Joined: Sun Jul 01, 2012 3:14 pm

Re: Rsync Help

Post by OhioYJ »

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 18
Level 18
Posts: 8501
Joined: Fri Sep 05, 2014 12:18 am
Location: Irish Brit in Portugal
Contact:

Re: Rsync Help

Post by smurphos »

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.
For custom Nemo actions, useful scripts for the Cinnamon desktop, and Cinnamox themes visit my Github pages.
OhioYJ
Level 1
Level 1
Posts: 36
Joined: Sun Jul 01, 2012 3:14 pm

Re: Rsync Help

Post by OhioYJ »

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.
WharfRat

Re: Rsync Help

Post by WharfRat »

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.
User avatar
smurphos
Level 18
Level 18
Posts: 8501
Joined: Fri Sep 05, 2014 12:18 am
Location: Irish Brit in Portugal
Contact:

Re: Rsync Help

Post by smurphos »

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:
For custom Nemo actions, useful scripts for the Cinnamon desktop, and Cinnamox themes visit my Github pages.
Locked

Return to “Scripts & Bash”