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 |
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.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
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.
 |
GNU/Linux Basic Guide
This 255-page guide will provide you with the keys to understand the philosophy of free software, teach you how to use and handle it, and give you the tools required to move easily in the world of GNU/Linux. Many users and administrators will be taking their first steps with this GNU/Linux Basic guide and it will show you how to approach and solve the problems you encounter.
Click Here to receive this Complete Guide absolutely free. |
|
 |
01-25-2007, 10:28 PM
|
#1
|
|
LQ Newbie
Registered: Jan 2007
Location: Quebec, Canada
Distribution: Mandriva One 2007
Posts: 6
Rep:
|
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.
|
|
|
|
01-26-2007, 01:12 AM
|
#2
|
|
Member
Registered: Sep 2006
Location: USA - NYC
Distribution: Whatever icon you see!
Posts: 642
Rep: 
|
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.
|
01-26-2007, 07:11 AM
|
#3
|
|
LQ Newbie
Registered: Jan 2007
Location: Quebec, Canada
Distribution: Mandriva One 2007
Posts: 6
Original Poster
Rep:
|
Thanks a bunch. I still have one more question, though. Can I have Cron do this each time I plug in the USB stick?
|
|
|
|
01-26-2007, 09:57 AM
|
#4
|
|
Member
Registered: Sep 2006
Location: USA - NYC
Distribution: Whatever icon you see!
Posts: 642
Rep: 
|
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.
|
|
|
|
01-27-2007, 03:26 PM
|
#5
|
|
LQ Newbie
Registered: Jan 2007
Location: Quebec, Canada
Distribution: Mandriva One 2007
Posts: 6
Original Poster
Rep:
|
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!
|
|
|
|
09-21-2007, 08:00 PM
|
#6
|
|
LQ Newbie
Registered: Sep 2007
Posts: 1
Rep:
|
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.
|
02-24-2009, 04:55 AM
|
#7
|
|
LQ Newbie
Registered: Jan 2005
Location: Germany
Distribution: SuSE Linux 9.2
Posts: 3
Rep:
|
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.
|
02-24-2009, 01:01 PM
|
#8
|
|
Member
Registered: Sep 2006
Location: USA - NYC
Distribution: Whatever icon you see!
Posts: 642
Rep: 
|
The post is more than two years old...
|
|
|
0 members found this post helpful.
|
03-14-2010, 10:39 PM
|
#9
|
|
LQ Newbie
Registered: Aug 2005
Posts: 14
Rep:
|
Quote:
Originally Posted by dv502
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.
|
|
|
|
03-14-2010, 11:16 PM
|
#10
|
|
LQ 5k Club
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian Squeeze (server), Slackware 13.37 (netbook), Slackware64 14.0 (desktop),
Posts: 8,367
|
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: - 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.
- All the ATTRS{*}== values must be taken from a single parent device.
- 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
- 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.
|
| Thread Tools |
Search this Thread |
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -5. The time now is 03:53 PM.
|
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|