LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Nebie with RSYNC (https://www.linuxquestions.org/questions/linux-newbie-8/nebie-with-rsync-4175428244/)

jim.thornton 09-20-2012 11:59 AM

Nebie with RSYNC
 
Okay... I have been using a laptop and a desktop. My laptop was setup first with Linux Mint and then my desktop a few months later also with Linux Mint.

When I setup my desktop, I copied over my Documents folder from my laptop. I have since used my laptop way more than my desktop and also for different tasks. So, my laptop has certain documents changed/updated since I copied it over to my desktop.

I'm starting to find it problematic to have two different computer/documents folders and would like to sync them up.

I was thinking that rsync will do what I need. However right now, what is the first command that I need to run to sync the documents folders. Here is what I would like to accomplish:

1. Copy any missing files from my laptop to my desktop
2. Copy any missing files from my desktop to my laptop
3. Update any files that are the same to the most recently modified file between the two computers.

I've been reading up on rsync a little but am not sure which terminology is correct for what I want.

suicidaleggroll 09-20-2012 12:16 PM

You can accomplish this with two rsync commands. rsync will automatically copy over new files and update files with an old timestamp in one move. So by issuing one rsync from laptop to desktop, you'll accomplish #1 and part of #3, then by issuing an rsync from desktop to laptop you'll accomplish #2 and the rest of #3. Issuing something like the following from the laptop should do it:

Code:

rsync -a ~/Documents desktop:~/Documents  # laptop to desktop
rsync -a desktop:~/Documents ~/Documents  # desktop to laptop

You should create a backup of the Documents directory on both the laptop and the desktop before running this, to make sure it doesn't have any undesired effects.
If you want this to happen automatically in the background, you could set up SSH keys to enable password-less login, and then run it in a cron job ever few minutes/hours.

Note that deleted or renamed files might start to become a problem. This is because when rsync runs, and it sees a local file that does not exist in the destination directory (or vice versa), it has no way of knowing whether this local file is new and should be copied over, or if it's been deleted or renamed on the destination and should therefore be deleted locally as well. This means that if you want to delete or rename a file, you'll need to do it on both the desktop and the laptop at the same time (at least before the rsync commands run again).

camorri 09-20-2012 12:16 PM

You can accomplish this task with rsync. This is how I back up my user files to my networked storage device.

When I set it up, I set up ssh first. You need sshd running on the destination box. I installed rsync, and a front end called 'grsync'. The front end helped me out a lot. You fill in the source directory, file, etc, and the target directory on the remote system. There are check boxes for Basic, and Advanced options. The nice thing is grsync saves your sync operations. So, if it a dir, or file you regularly need to update, rsync will have a list of your common updates. It made it simple for me.

The nice thing about rsync, is if you make small changes to files, the entire file doesn't get copied, only the changes get copied to the target file. That makes it fast, once the first backups are done. There is an option to 'Simulate' the update. If you have made errors, it will let you know; before you borke up the target. I like it.

jim.thornton 09-20-2012 12:22 PM

How is it possible to only update the changes of a file. For a Word (.doc) file for example, it isn't just a text file, so how would it know how to update the changes of the file without messing up the file structure?

Also... The -a option, isn't that for archive? Not sure what that does. Finally, should I do -r as well to ensure all of the subdirectories are also synced?

suicidaleggroll 09-20-2012 12:25 PM

Quote:

Originally Posted by jim.thornton (Post 4785247)
Also... The -a option, isn't that for archive? Not sure what that does. Finally, should I do -r as well to ensure all of the subdirectories are also synced?

Yes, -a stands for archive, but all it is is a shortcut for other commonly used flags, namely -rlptgoD

-r = recursive
-l = copy symlinks as symlinks
-p = preserve permissions
-t = preserve modification times
-g = preserve group
-o = preserve owner
-D = preserve device files and special files

JaseP 09-20-2012 12:40 PM

If you want the ease of a graphical setup, consider using grsync. Also, you should use anacron instead of cron, for the rysnc job, as a laptop is unlikely to be on 24/7... Actually, and more properly, use cron to run an anacron job to do the backups,... That way you can specify they get done if the system was off, and periodically check that they were run if the system was active... When the system boots, anacron will be there to run a missed job for you, if you have it set that way...

camorri 09-20-2012 12:40 PM

Quote:

How is it possible to only update the changes of a file. For a Word (.doc) file for example, it isn't just a text file, so how would it know how to update the changes of the file without messing up the file structure?
How it works, I can not comment on. I suggest you go her -->http://rsync.samba.org/ there is a lot of good info, examples, doc, and FAQ etc.

jsaravana87 09-20-2012 12:41 PM

#Its incremental backup : most recently modified file between the two computers.

These command seems to backup only the recent made changes from source to destination folder

# rsync -zavi root@ipadress:/source /destination

jim.thornton 09-20-2012 01:15 PM

That's awesome... Thanks for the help!


All times are GMT -5. The time now is 05:21 AM.