LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices

Reply
 
Search this Thread
Old 01-25-2007, 10:28 PM   #1
Valandil
LQ Newbie
 
Registered: Jan 2007
Location: Quebec, Canada
Distribution: Mandriva One 2007
Posts: 6

Rep: Reputation: 0
Sync a USB flash drive with HD folders, possible?


Hello there!

I would like to know if there is a way to tell my distro (Mandriva One 2007) that I want my USB stick to synchronize a certain folder it contains with a certain folder my HD contains. By synchronizing, I mean that I want files, for instance on the USB stick, that have been edited more recently that those on the HD replace the one existing on the HD. I guess it is possible with Cron, but since I am a not yet a pro with the shell commands, I need some help out there.

If you need more clarity, just tell me.

Thanks in advance!

P.-S. By the way, I hope my English is not too bad, I'm from Quebec, the last fortress of French in Canada, meh.
 
Old 01-26-2007, 01:12 AM   #2
dv502
Member
 
Registered: Sep 2006
Location: USA - NYC
Distribution: Whatever icon you see!
Posts: 642

Rep: Reputation: 57
You can use the rsync command to synchronize folders.

rsync -a source --delete destination

The source and destination represents the paths to your folders.

An example:

rsync -a /mnt/sda1/ --delete /home/user/some_dir

-a will archive all folders and subdirectories
--delete will synchronize folders

The /mnt/sda1 is a usb stick, it will have the recent updated files. Rsync will make a duplicate copy of
/mnt/sda1 to /home/user/some_dir

Use the --delete with caution! This will delete files
from the destination path not found in the source path.

In other words, files updated or deleted from the source will be applied equally to the destination.

Practice first.

You can do the same thing without the --delete option. This will keep the files on both sides updated, but nothing is deleted.

Last edited by dv502; 01-26-2007 at 01:25 AM.
 
2 members found this post helpful.
Old 01-26-2007, 07:11 AM   #3
Valandil
LQ Newbie
 
Registered: Jan 2007
Location: Quebec, Canada
Distribution: Mandriva One 2007
Posts: 6

Original Poster
Rep: Reputation: 0
Thanks a bunch. I still have one more question, though. Can I have Cron do this each time I plug in the USB stick?
 
Old 01-26-2007, 09:57 AM   #4
dv502
Member
 
Registered: Sep 2006
Location: USA - NYC
Distribution: Whatever icon you see!
Posts: 642

Rep: Reputation: 57
No. Cron does not detect nor mount devices. Cron is a schedular program. You can use cron to schedule
tasks at specific times. You can use cron to do
synchronizing of your usb stick and folder at certain
time schedules. Just make sure the usb stick is mounted before cron runs its schedule time.

Do a google search on linux cron setup or how to.

Hope it works

Last edited by dv502; 01-26-2007 at 10:18 AM.
 
Old 01-27-2007, 03:26 PM   #5
Valandil
LQ Newbie
 
Registered: Jan 2007
Location: Quebec, Canada
Distribution: Mandriva One 2007
Posts: 6

Original Poster
Rep: Reputation: 0
Thanks guys!

I fould something that would permit me to do what I want. There are udev rules that makesa backup of all the data on a USB stick to the HD, it seems. I can meld the rsync feature with this so it will do it automatically.

See ya!
 
Old 09-21-2007, 08:00 PM   #6
scribe777
LQ Newbie
 
Registered: Sep 2007
Posts: 1

Rep: Reputation: 0
Correct Options: "sync preferring newest"

Hey guys. I came to this thread seeking the same advice: How to SYNC USB drive folder with system drive folder, always preferring newest files. After playing with rsync, -av will not SYNC preferring newest. It will always overwrite dest files with source files-- even if dest files are newer. The two commands I run to SYNC two folders preferring newest are:

rsync -avuz source/ dest/
rsync -avuz dest/ source/


This will assure both folders are in sync with latest files always being used.

NOTE: the trailing '/' is also important!

'avuz' sounds like something. I guess you could also remember 'zuva'

Hope this helps.
 
1 members found this post helpful.
Old 02-24-2009, 04:55 AM   #7
welle
LQ Newbie
 
Registered: Jan 2005
Location: Germany
Distribution: SuSE Linux 9.2
Posts: 3

Rep: Reputation: 0
usbsync

There is a nicely convenient tool called usbsync which has specially been desgined for the purpose of keeping a usb flash drive in sync with multiple Unix hosts.

Check it out at http://klingspor-thueringen.de/usbsync

Cheers,
welle
 
1 members found this post helpful.
Old 02-24-2009, 01:01 PM   #8
dv502
Member
 
Registered: Sep 2006
Location: USA - NYC
Distribution: Whatever icon you see!
Posts: 642

Rep: Reputation: 57
The post is more than two years old...
 
0 members found this post helpful.
Old 03-14-2010, 10:39 PM   #9
bobpaul
LQ Newbie
 
Registered: Aug 2005
Posts: 14

Rep: Reputation: 0
Quote:
Originally Posted by dv502 View Post
The post is more than two years old...
Good call, cause rsync, udev, and usbsync are no longer useful tools... oh... wait.

welle: Thanks for the tip! I was going to script something myself, but usbsync's working great.
 
Old 03-14-2010, 11:16 PM   #10
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Servers: Debian Squeeze and Wheezy. Desktop: Slackware64 14.0. Netbook: Slackware 13.37
Posts: 8,551
Blog Entries: 28

Rep: Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176
Here's a sample udev rule (/etc/udev/rules.d/90-local.rules) in case anyone wants to automate running a script on plugging in a USB HDD
Code:
# Hitachi SimpleDrive mini, model HTS545050B9A300 (500 GB USB HDD)
SUBSYSTEM=="block", ATTR{size}=="976768002", ATTRS{product}=="SimpleDrive mini", ATTRS{serial}=="2512009121920487", ACTION=="add", RUN+="/lib/udev/local.usb.hdd.sh add $devpath"
Notes:
  1. Values used in ATTR{*}== and ATTRS{*}== can be found when the device is plugged in by running udevadm info -a -p /sys/block/sdc/sdc1, replacing sdc and sdc1 with appropriate values.
  2. All the ATTRS{*}== values must be taken from a single parent device.
  3. The called script can determine the /dev/sd* device file to use in mounting by
    Code:
    maj_min="$(cat "/sys$devpath/dev")"
    buf="$(ls -l "/dev/block/$maj_min")"
    dev_file="/dev/${buf##*/}"
    mount $dev_file $mountpoint
  4. When udev runs such a script it captures stdout (and stderr?). For debugging they can be redirected to somewhere visible.

Last edited by catkin; 03-14-2010 at 11:18 PM. Reason: Added buf="$(ls -l "/dev/block/$maj_min")"
 
1 members found this post helpful.
  


Reply

Tags
drive, flash, hard, sync, usb


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Using a usb thumb drive or flash drive as a swap partition. stevenjoseph Linux - Hardware 8 01-16-2012 12:09 PM
USB Pen Drive / Flash Drive Unmounted but the power is there teluguswan Linux - Hardware 11 10-04-2008 03:36 PM
USB flash drive (Pen drive) mounts read only prabhatsoni Linux - Hardware 24 07-02-2007 01:28 PM
Mount an USB-Drive sync ToK Ubuntu 4 03-08-2006 03:14 AM
Usb drive file sync pembo13 Linux - General 2 11-11-2004 09:56 PM


All times are GMT -5. The time now is 06:39 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration