sync between two devices

Place to discuss Fedora and/or Red Hat
Post Reply
X11
guru
guru
Posts: 676
Joined: Sun Jan 19, 2003 11:09 pm
Location: Australia
Contact:

sync between two devices

Post by X11 » Sun May 28, 2006 10:24 am

I was interested in some kind of script to sync between a USB memory stick and a directory called "Sync" in my homedir. The idea of this is that I create a bunch of symlinks to thinks, and click and launcher on the desktop and run the script, and things go smoothly. Then I eject my device, and walk away knowing my files are safe.

So I wrote a script to do this, and it works all perfectly well...

Code: Select all

[x11@kintaro64 ~]$ cat Toolkit/usbsync.sh
#!/bin/sh

DEVFOLDER="Kintaro"

DEVICE="/media/disk/$DEVFOLDER"

echo "Doing sync from $USER homedir $DEVICE"
cp -vRu ~/Sync/* $DEVICE
echo "Doing sync from $DEVICE to $USER"
cp -vRu $DEVICE/* ~/Sync/
The only problem this script here has is that, I cannot DELETE anything without it syncing back to the other.

So I was curious as to some pointers on what I should use, to stop being so lazy. I was thinking of rsync or something like that, but I want something as simple as possible to do the job, so I was curious as to suggestions of what software I should use.

Tux
guru
guru
Posts: 689
Joined: Wed Jan 08, 2003 10:40 am

Post by Tux » Sun May 28, 2006 12:56 pm

You know, I was looking for something to do the same thing a few months ago. Lo and behold I did find something, but I never got round to using it and have forgotten the name of it :-O

It will be in my old bookmarks somewhere, I will dig it out sometime this week for you.

User avatar
Void Main
Site Admin
Site Admin
Posts: 5712
Joined: Wed Jan 08, 2003 5:24 am
Location: Tuxville, USA
Contact:

Post by Void Main » Sun May 28, 2006 2:43 pm

I use rsync for this which not only works across devices but also can sync to remote machines. It has plenty of options depending on what you need (delete, no delete, skip certain files, etc).

Master of Reality
guru
guru
Posts: 562
Joined: Thu Jan 09, 2003 8:25 pm

Post by Master of Reality » Sun Jun 11, 2006 5:26 pm

I'm doin pretty much the same thing. I use rsync to synchronize my USB key from my laptop or from my desktop so i have all my school notes with me.

I use the update option because i dont want any files deleted, but it updates any file with a modified time older or the same.

Since this updates every file each time (because they will have the same modified time) it can be lengthy.

Is there some way to make it update only files with an older modified time?[/b]

Code: Select all

#!/bin/bash
echo "Syncing from local folder to USB-drive"
rsync -ru --progress /home/mor/rcc/ /media/disk/notes/
echo "Syncing from USB-drive to local folder"
rsync -ru --progress /media/disk/rcc/ /home/mor/notes/

User avatar
Void Main
Site Admin
Site Admin
Posts: 5712
Joined: Wed Jan 08, 2003 5:24 am
Location: Tuxville, USA
Contact:

Post by Void Main » Sun Jun 11, 2006 5:41 pm

It shouldn't update a file that hasn't been modified. I can't imagine why it would for you. It should only update changed files, and then it will only update the parts of the file that has changed and not the entire file which is why it is usually much faster than any other tool for updates. I always just use the "-a" switch (archive).

Master of Reality
guru
guru
Posts: 562
Joined: Thu Jan 09, 2003 8:25 pm

Post by Master of Reality » Wed Jun 14, 2006 6:36 pm

i realized why it was doing the thing with the mod times... It couldnt actually do the archive option because i have it formatted as fat16 at the moment... soon to be ext3

Master of Reality
guru
guru
Posts: 562
Joined: Thu Jan 09, 2003 8:25 pm

Post by Master of Reality » Wed Jun 21, 2006 7:41 pm

weird problem now... I'm running that command, but after it starts transferring stuff, fedora seems to automatically change it to be mounted as read-only. Is this some sort of weird feature of fedora for something?

User avatar
Void Main
Site Admin
Site Admin
Posts: 5712
Joined: Wed Jan 08, 2003 5:24 am
Location: Tuxville, USA
Contact:

Post by Void Main » Wed Jun 21, 2006 7:54 pm

Need more information to compute.

Master of Reality
guru
guru
Posts: 562
Joined: Thu Jan 09, 2003 8:25 pm

Post by Master of Reality » Thu Jun 22, 2006 6:53 am

erm...
Using a mr. flash 256 Mb usb stick.
I plug it in and either let it automount or, i mount it myself ( i tried both ways).
Then i did "touch /media/disk/test" to see if i could write to it (and i can)
then i did 'rsync -ru --progress /home/mor/rcc/ /media/disk/rcc/' (as a user)

when that commands starts, sometimes it copies a couple files, but then puts the mounted partition in read-only.

rsync gives me this error:

Code: Select all

[mor@blue ~]$ rsync -ru --progress /home/mor/rcc/ /media/disk/rcc/
building file list ...
14858 files to consider
engl130/groupres/.conformitykills.png.awwkXW
rsync: writefd_unbuffered failed to write 4 bytes [sender]: Broken pipe (32)
rsync: write failed on "/media/disk/rcc/engl130/groupres/.conformitykills.png.awwkXW": Input/output error (5)
rsync: connection unexpectedly closed (322785 bytes received so far) [generator]
rsync error: error in rsync protocol data stream (code 12) at io.c(463) [generator=2.6.8]
rsync: connection unexpectedly closed (30 bytes received so far) [sender]
rsync error: error in rsync protocol data stream (code 12) at io.c(463) [sender=2.6.8]
and when i try to do a "touch /media/disk/test" it tells me its read-only filesystem.

/media/disk (/dev/sda1) is ext3 filesystem. There is also a 10M fat16 partition at /dev/sda2

Master of Reality
guru
guru
Posts: 562
Joined: Thu Jan 09, 2003 8:25 pm

Post by Master of Reality » Thu Jun 22, 2006 9:35 am

i did an fsck on it, i think it may be a corrupted partition (fsck tells me that may be when it starts and asks to abort the check). So erased the partition table and remade it, and the filesystems.

User avatar
Void Main
Site Admin
Site Admin
Posts: 5712
Joined: Wed Jan 08, 2003 5:24 am
Location: Tuxville, USA
Contact:

Post by Void Main » Thu Jun 22, 2006 10:43 am

Yeah, that doesn't sound like an rsync issue but either a hardware (memstick) or kernel module issue. Anything in "dmesg" output or /var/log/messages after it does this?

Tux
guru
guru
Posts: 689
Joined: Wed Jan 08, 2003 10:40 am

Post by Tux » Mon Jul 03, 2006 4:27 pm


Post Reply