LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   backing up text files distributed throughout the drive (https://www.linuxquestions.org/questions/linux-newbie-8/backing-up-text-files-distributed-throughout-the-drive-532969/)

pmetzak 02-27-2007 11:48 AM

backing up text files distributed throughout the drive
 
Hi,

I am attempting to back up a bunch of .m files that are located all over the 2 hard drives (these .m files are text files run by matlab). I have been doing a bit of research and its seems like cpio might be a good option.

Is this the command that I would use?

find -name "*.m" -print | cpio -ov > mfiles2007.cpio

Is there a better way to accomplish what I am setting out to do?

Thanks for any help you can offer me.

Paul

SciYro 02-27-2007 12:40 PM

My advise: Test the command out on a test collection first, just to be safe. Other then that i cant say, as cpio has no man page because GNU doesn't like man pages, so i have no clue if that command will work.

dgar 02-27-2007 12:52 PM

It will work if you can guarantee that no directories or file names have spaces in them, unless CPIO handles spaces in stdin streams....

I'd use:
locate -r '\.mp3$' > filelist.txt
for line in $(cat filelist.txt); do
cp -v "$line" /some/destination/
done 2>&1 | tee copy_report.txt

pmetzak 02-27-2007 02:53 PM

I'm sorry, I don't really understand this:

locate -r '\.mp3$' > filelist.txt
for line in $(cat filelist.txt); do
cp -v "$line" /some/destination/
done 2>&1 | tee copy_report.txt

Is this 2 commands separated by the semi-colon? Also, I only want .m files not .mp3's but I can figure out the substitution to make there myself :)

Once again, I apologize for my ignorance,

Paul

Quakeboy02 02-27-2007 03:50 PM

"find /data -name "*.ogg" -print | cpio -ov > test.cpio"

I just ran this against the ogg files in my data disk. They have embedded spaces, and it seemed to work just fine. I did a "cpio -tv < test.cpio", and it listed the files I expected, having substituted "\ " for the embedded spaces. Sometimes you just have to do it and see if it works. :)

Added:
Almost forgot: the man page sucks, but "cpio --help" or "cpio --usage" gives a lot of help.

dgar 02-28-2007 08:22 AM

The 'find <options> | cpio <options>' is the most powerful, but also two of the oldest and most archaic commands in /usr/bin/*.

Let me break down my method:

locate -r '\.mp3$' > filelist.txt
# There is a database updated nightly of all filenames.
# The above makes a list of all files ending in '.mp3'
# The advantage is that you can just edit the list. b)

for line in $(cat filelist.txt); do
# This assigns each line of filelist.txt to $line.
# The semicolon is just a stylistic shorthand.

cp -v "$line" /some/destination/
# The meat of the command.
# I actually run 'cp -vn' first which
# pretends to copy, but doesn't actually do it.

done 2>&1 | tee copy_report.txt
# Some UNIX magic here. This ends the looping
# over filenames.txt and forks the output of
# 'cp -v' to both the screen and a logfile.


All times are GMT -5. The time now is 10:44 PM.