[SOLVED] A good rsync tutorial?

Quick to answer questions about finding your way around Linux Mint as a new user.
Forum rules
There are no such things as "stupid" questions. However if you think your question is a bit stupid, then this is the right place for you to post it. Stick to easy to-the-point questions that you feel people can answer fast. For long and complicated questions use the other forums in the support section.
Before you post read how to get help. Topics in this forum are automatically closed 6 months after creation.
Locked
sneakyfox
Level 2
Level 2
Posts: 58
Joined: Sun Jul 19, 2020 7:15 am

[SOLVED] A good rsync tutorial?

Post by sneakyfox »

I've heard rsync is a great tool. Can anyone recommend a good tutorial on how to use it and what to use it for?

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.
rene
Level 20
Level 20
Posts: 12240
Joined: Sun Mar 27, 2016 6:58 pm

Re: A good rsync tutorial?

Post by rene »

rsync, although it can be used via its own rsync network protocol as well, should preferably be considered a fancy version of cp. Frankly most that you need to know about is is contained in

Code: Select all

rsync -av /path/to/source /desti/nation/
Something you should learn early on about its syntax is the issue concerning trailing slashes or not: an operand /path/name denotes the file or directory /path/name whereas /path/name/ denotes the content of directory /path/name. If it's not immediately clear why you want to know that already just keep it in mind.

As to what you use this fancy cp for, then, is to do fancy copying. Which may for example include from or to via an SSH reachable destination simply as

Code: Select all

rsync -av /path/to/source machine:/desti/nation/
and certainly tends to include syncing/backups if including e.g. --delete in that command line. A good "tutorial" I could not recommend, but man rsync is useful as to what its options do. You'll often not in fact need/want many --- but there are tons.
User avatar
AndyMH
Level 21
Level 21
Posts: 13575
Joined: Fri Mar 04, 2016 5:23 pm
Location: Wiltshire

Re: A good rsync tutorial?

Post by AndyMH »

Read the man pages and pay attention to include/excludes. The order you specify them matters.
Thinkcentre M720Q - LM21.3 cinnamon, 4 x T430 - LM21.3 cinnamon, Homebrew desktop i5-8400+GTX1080 Cinnamon 19.0
cliffcoggin
Level 8
Level 8
Posts: 2300
Joined: Sat Sep 17, 2016 6:40 pm
Location: England

Re: A good rsync tutorial?

Post by cliffcoggin »

rene wrote: Wed Apr 21, 2021 5:39 am Something you should learn early on about its syntax is the issue concerning trailing slashes or not: an operand /path/name denotes the file or directory /path/name whereas /path/name/ denotes the content of directory /path/name. If it's not immediately clear why you want to know that already just keep it in mind.
Not wishing to hijack this discussion, but the matter of trailing slashes is relevant to it. Despite reading many guides over the years I struggled to comprehend the use of trailing slashes when it comes restoring a Home backup using Grsync. I now believe, and hope, that the lack of a / at the end of the destination creates a Home folder; whereas a / at the end restores to the existing Home folder. Am I wrong?
Cliff Coggin
rene
Level 20
Level 20
Posts: 12240
Joined: Sun Mar 27, 2016 6:58 pm

Re: A good rsync tutorial?

Post by rene »

The first part of that seems about right, Specifically (and all of these first while assuming that the destination does not yet exist),

Code: Select all

rsync -av /data/backup/cliff /home/cliff
would create /home/cliff to be a copy of /data/backup/cliff in the same way that

Code: Select all

rsync -av /data/backup/cliff /home/
would. That syntax however also immediately says/implies that the second part of what you said is not in and of itself correct, depending on the syntax for the source parameter. I.e.,

Code: Select all

rsync -av /data/backup/cliff /home/cliff/
would create a directory /home/cliff/cliff (to be a copy of etc.). If you on the other hand say

Code: Select all

rsync -av /data/backup/cliff/ /home/cliff/
then you restore the contents of /data/backup/cliff to an existing directory /home/cliff --- which is presumedly what you generally want.

Do correct me if I'm wrong but I believe that if you just always vocalise/translate an ending slash in the context of rsync as "the content of" that you're okay (although there are still annoying potential differences between the cases of an already existing and nonexisting destination parameter that I've also stumbled over at times).
cliffcoggin
Level 8
Level 8
Posts: 2300
Joined: Sat Sep 17, 2016 6:40 pm
Location: England

Re: A good rsync tutorial?

Post by cliffcoggin »

Thanks Rene. I feel the need to experiment.
Cliff Coggin
rickNS
Level 9
Level 9
Posts: 2914
Joined: Tue Jan 25, 2011 11:59 pm

Re: A good rsync tutorial?

Post by rickNS »

rsync is a great tool. a lot of backup software is based on it.

10 practical examples,
https://www.tecmint.com/rsync-local-rem ... -commands/

IMO a "must know" for anyone with more than one pc.
I use it often to send a file to (or get a file from) another computer (rather than using USB sticks)
To keep the command simple, I create a top level directory like ~/send , or ~/ship etc., and place what ever I want to send in it. Since I have the same user name on all machines, the command is very short.
Basically,
rsync -ahv ~/send/ 192.xxx.x.xxx:~/send
That's pretty easy.
Note the trailing slash, as mentioned, that's so you don't create another "level".
If you did have a different username on another machine you add username@ in front of the ip address.
Mint 20.0, and 21.0 MATE on Thinkpads, 3 X T420, T450, T470, and X200
sneakyfox
Level 2
Level 2
Posts: 58
Joined: Sun Jul 19, 2020 7:15 am

Re: A good rsync tutorial?

Post by sneakyfox »

Thank you for all the interesting posts, including the examples. That will do for me :)
Locked

Return to “Beginner Questions”