LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Slackware (http://www.linuxquestions.org/questions/slackware-14/)
-   -   Need to syncronize to folders on laptop and usb memory stick (http://www.linuxquestions.org/questions/slackware-14/need-to-syncronize-to-folders-on-laptop-and-usb-memory-stick-4175457230/)

longus 04-07-2013 09:25 AM

Need to syncronize to folders on laptop and usb memory stick
 
Hello! A have an issue and i hope there is a simple decision.
I need to synchronize a folder on my laptop with a folder on an usb flash drive.
I think the same solution should be appropriate also to synchronize my phone pics with the desktop.
I need something simple that works without internet connection, i.e. when i insert the usb stick, the program must synchronize the files bidirectionally. Also in that case it is important to me to have control about the direction. Sometimes i write something on my laptop and go to print the file (transmitting the file through the usb stick), but in other case i have to edit some document, or gen it, from the office computer and then move the copy on my laptop. The way to manually copy and paste is sometimes boring and leads to mistakes.
Any suggestion should be appreciated!

mariostg 04-07-2013 09:42 AM

Have you tried unison : "Unison is a file-synchronization tool for Unix and Windows". It's in Slackbuilds

eloi 04-07-2013 11:43 AM

Assuming you have mounted the flash drive in /media/memory/

Code:

$ rsync -rLptDvu --delete /HDD/directory/ /media/memory/directory/
                                        ^                        ^
                                          (add the last slashes)

will copy form your machine to the flash drive. And

Code:

$ rsync -rLptDvu --delete /media/memory/directory/ /HDD/directory/
will do the opposite.


To fine tune:

Code:

$ man rsync

longus 04-07-2013 12:58 PM

Quote:

Originally Posted by mariostg (Post 4926862)
Have you tried unison : "Unison is a file-synchronization tool for Unix and Windows". It's in Slackbuilds

Thank you! It seems a good tool. Anyway is there a daemon mode of unison?

eloi, thank you too for the replay! rsync is also a solution. Probably i should try that too assigned to shortkeys.

mariostg 04-07-2013 01:51 PM

@longus
Not sure if unison has daemon mode. I know it operates either from the console or GUI, advise you of potential conflicts and operate bidirectionally. rsync is good too but I don't think it helps in file conflict resolution and does not work bidirectionally.

Mark Pettit 04-07-2013 02:53 PM

Unison is great - but quite complex to setup. I strongly suggest you look at the rsync tips above.

mariostg 04-07-2013 03:08 PM

@Mark
Maybe I don't use it to its full extend, but I found Unison rather easy to set up. I found the wizard simple then after a set up I figured it is just a easier and faster to write my own prf files:
Quote:

>>>cat .unison/books.prf
label = Sync with xeon
root = /home/marst/books
root = ssh://marst@10.0.0.5//home/marst/books
sshargs = -p 2222
fat = true

longus 04-07-2013 03:42 PM

Actually it is quite simple to setup. I have tried it.

Well, one question remain. The usb stick must be mounted before starting the unison in XFCE, otherwise it cant fount the drive. I avoid the automounting in XFCE because it mounts my 3G modem as a storage drive.

One more question. Does slackware-14 mount this usb stick on the same location in /run directory every time?

Still searching something like daemon automatically starting the process of synchronization.
rsync can't offer an option to control, i.e. to choose which file in which direction to update.

eloi 04-07-2013 04:32 PM

Quote:

Originally Posted by mariostg (Post 4927004)
@longus
Not sure if unison has daemon mode. I know it operates either from the console or GUI, advise you of potential conflicts and operate bidirectionally. rsync is good too but I don't think it helps in file conflict resolution and does not work bidirectionally.

I don't know what you mean by "conflict resolution".

About "bidirectionally" the only I can say is that the rsync options I've used above respect modification time. So running both commands rsync will copy newer versions in both directories. Then if modification time is your interest and assuming the other machines you plug the usb memory use the same time zone and clock settings that two commands should do the job.

Do not hesitate in telling me if I forget something. Four eyes see better than two :).

Anyway, in general terms, if the flash drive will jump from some annoying OS to another worse I think, honestly, that sync *from* the flash drive is not advisable.

mariostg 04-07-2013 08:46 PM

@eloi :)
Simply means that if per example a file has gone AWOL unison will not know "which whay" the synchronize should be. So it will be to the user to decide what to do i.e. skip or restore at the destination where missing.

Don't get me wrong, I use rsync if I want to move files in only one way, but I will use unison if I want to synchronize. It just makes me feel safer.

And I only rsync/unison between Linux boxes... I stay away from OS that gets into my way :)

Mark Pettit 04-08-2013 01:10 AM

Conflict resolution : There are several ways in which Unison can break. We use Unison to transfer files between 4 companies, across Windows, Linux and Solaris. We love Unison and would be hard pressed to get by without it. But even so, it does trip up over some issues, which are not trivial to solve. I'll describe some - they may not apply in your case. But do note that technically Unison is a distributed file system, with (relatively) high latency between updates. (in comparison to say a mirrored SAN disk system).
Case 1) User on side (a) updates a file and at the same time a user on suide (b) updates the same file. As Unison is essentially master-master, it can't decide which is the real "latest" file and even if it chooses (which it doesn't), someone will be unhappy.
Case 2) Two files "aaa.txt" and "AAA.TXT" are created on Unix/Linux side and are synced to a single Windows machine - instant fail as Windows is case-insensitive.

Now, if you're using a "simple" setup to your own USB disk, then chances are that you'll be fine. But be aware that there's more to Unison than meets the eye.

eloi 04-08-2013 05:19 AM

Quote:

Originally Posted by mariostg (Post 4927220)
@eloi :)
Simply means that if per example a file has gone AWOL unison will not know "which whay" the synchronize should be. So it will be to the user to decide what to do i.e. skip or restore at the destination where missing.

You're right. I've never though about bidirectional sync. Now I see that the option --delete is a problem.

I've found this:

http://superuser.com/questions/16631...omparing-files

You could run:

Code:

$ find /HDD/directory -printf "%P\n" | sort > /tmp/file1
$ find /media/memory/directory -printf "%P\n" | sort | diff - /tmp/file1

and manually remove from that list the files you don't want to keep before using rsync in both directions without the --delete option.

But there is one more problem I can't think of an easy, practical solution, the rare case of files with same name, time but different content.

Finally, I insist, even if you use it just on Linux boxes, rely on sync *from* a flash drive is not a good idea.


All times are GMT -5. The time now is 07:01 AM.