[SOLVED] rsync two directories, slashes at ends of paths or not
Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
rsync two directories, slashes at ends of paths or not
I tried searching this on the web and see it different all over. My source folder is on the server I'm running rsync from. The folder is /data/pictures which has many subfolders. On my 1.2.3.4 server, I want to recreate pictures and all its subfolders inside of 1.2.3.4's /backups/pics-backup folder. When do I need to put a slash at the end of the folder paths and when don't I?
I think what I want to do is below, but searching on the web for when to put the trailing slash on the path has confused me as to what is right.
rsync -r -a -z -p -e ssh /data/pictures user@1.2.3.4:/backups/pics-backup/
I think the rsync man page said it best and helped me understand it:
A trailing slash on the source changes this behavior to avoid creating an additional directory level at the destination. You can think of a trailing / on a source as meaning “copy the contents of this directory”.
So, the example that they give can be explained in this way:
rsync -av /src/foo /dest
Copy the directory by name and it's contents into /dest, creating the folder foo and what it contains in /dest.
rsync -av /src/foo/ /dest/foo
Copy the contents of the directory into the folder /dest/foo. You are not necessarily copying the actual folder foo. The destination folder can be named anything and what was contained in foo will be copied to it.
If you do not want an additional directory depth in your backup (/backups/pics-backup/pictures) you would do:
rsync -r -a -z -p -e ssh /data/pictures/ user@1.2.3.4:/backups/pics-backup
If you did want that extra pictures folder inside pics-backup, you would do:
rsync -r -a -z -p -e ssh /data/pictures user@1.2.3.4:/backups/pics-backup/
Yeah, I do want the extra pictures folder, just in case I'd ever have to copy it back, I can just move that pictures folder in its entirety. Thanks guys!
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.