LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 01-22-2010, 06:17 PM   #1
Tamaros
LQ Newbie
 
Registered: May 2008
Posts: 12

Rep: Reputation: 0
Scripting help copying files from a NTFS partition


I record my lectures at school using my mobile phone then send them over wifi to my laptop and use a program to do volume correction all in windows. However, I want a exact copy of that folder in my home folder on my ubuntu install on a separate partition.

I've been manually copying them over so far but I want to make a script that I can run to copy all new files over.

I know a little bit about scripting, mounting the drive and actually copying files is easy, its figuring out how to determine new files and copy only those that I don't know how to do.
 
Old 01-22-2010, 08:21 PM   #2
antegallya
Member
 
Registered: Jun 2008
Location: Belgium
Distribution: Debian
Posts: 109

Rep: Reputation: 42
Hello,

there's a great tool for file synchronisation that will determine which are new or changed. It's name is rsync. There's plenty of options.
Note that it's not usually installed by default so :
Code:
sudo apt-get install rsync
This would do the trick (have a look at man rsync for details) :
Code:
rsync -a source_directory destination_directory
(It only helps for the file synchronisation, you still need to mount your partition)

Hope it helps.
 
Old 01-23-2010, 01:56 AM   #3
Tamaros
LQ Newbie
 
Registered: May 2008
Posts: 12

Original Poster
Rep: Reputation: 0
I thought I had this one in the bag!

OK . . .

I set a variable for the source directory, something like

Code:
 NTFS=/mnt/ntfs/Users/name/Documents/School/Spring\ 2010/
and a source directory of

Code:
 /home/name/School/Spring\ 2010/
then I'm calling rsync with

Code:
rsync -ar --progress $NTFS $DEST
I added the 'r' for recursive because within the 'Spring 2010' directory I have a directory for each class and then a directory for lectures and other related documents etc., etc.

It didn't react as I expected. In the man page i read something about "--protect-args (-s)" in relation to whitespace so I added that


Code:
rsync -ars --progress $NTFS $DEST
Same exact behavior.

Code:
sending incremental file list
rsync: link_stat "/mnt/ntfs/Users/name/Documents/School/Spring" failed: No such file or directory (2)
rsync: change_dir "/home/name/Desktop/2010" failed: No such file or directory (2)
rsync: link_stat "/home/name/School/Spring" failed: No such file or directory (2)
created directory 2010

sent 18 bytes  received 12 bytes  60.00 bytes/sec
total size is 0  speedup is 0.00
rsync error: some files/attrs were not transferred (see previous errors) (code 23) at main.c(1057) [sender=3.0.6]
I have the script file located on the desktop which is the only explanation i can think of for it to show '/home/name/Desktop/' as a file path in any of the errors. I had thought that using absolute file-paths would make the location of the script itself irrelevant (or did I do that incorrectly)

the directory 2010 referenced at the end of the output was created on the Desktop as well.

Here's the whole script if that helps anyone help me.

Code:
#!/bin/bash

# lecturesync, version 1

# invoke with 'sudo'

# mount point stored in variable
MNT_DIR=/mnt/ntfs

# hard drive device identifier
HD=/dev/sda2

# ntfs source directory
NTFS=/mnt/ntfs/Users/name/Documents/School/Spring\ 2010/

# destination directory
DEST=/home/name/School/Spring\ 2010/

# mount the Win7 ntfs drive
mount -t ntfs $HD $MNT_DIR

# sync the files
rsync -ars --progress $NTFS $DEST
 
Old 01-23-2010, 08:18 AM   #4
antegallya
Member
 
Registered: Jun 2008
Location: Belgium
Distribution: Debian
Posts: 109

Rep: Reputation: 42
Hello,

that's only a little problem of escapes and substitution. In fact when you set
Code:
$ DEST=/home/name/School/Spring\ 2010/
$ echo $DEST
/home/name/School/Spring 2010/
So the rsync command you are using don't use escaped spaces. Think of the subsitution the shell does, after substituting the executed command line is :
Code:
rsync -ars --progress /mnt/ntfs/Users/name/Documents/School/Spring 2010/
 /home/name/School/Spring 2010/
The -s option is protection of the spaces to pass to the remote host, it doesn't affect the parsing of rsync args.

The solution is simply to add quotes
Code:
rsync -as --progress "$NTFS" "$DEST"
Note that I removed the -r option, because it is implied by -a. Following the man page :
Quote:
-a, --archive archive mode; equals -rlptgoD (no -H,-A,-X)
Hope it works now.
 
Old 01-23-2010, 10:44 AM   #5
Tamaros
LQ Newbie
 
Registered: May 2008
Posts: 12

Original Poster
Rep: Reputation: 0
Worked like a charm!

Thank you very much.
 
  


Reply

Tags
scripting, ubuntu


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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
problem with copying data from a (western digital) usb drive (ntfs partition) piyush.popli Fedora 4 02-23-2009 05:40 AM
having trouble copying files from ntfs partition Lord Xeb Linux - Newbie 3 01-27-2009 12:25 PM
Knoppix: copying files from NTFS to FAT32 Manhhh Linux - Newbie 6 08-25-2005 04:21 PM
Copying files to WinXP(NTFS)partition WindowsBurner Linux - General 14 11-11-2003 09:53 AM
I/O error when copying (some) NTFS files cherup Linux - Newbie 1 05-21-2003 05:20 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 04:25 PM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration