Filename collision during backup

Thread Tools Search this Thread
# 1  
Filename collision during backup


I am trying to backup all *.tar files from a legacy Linux to a portable harddrive.

find . -name "*.tar" -exec cp {} /media/mypassport/backup \;

I found that there are files with the same filenames and they were overwritten
in the destination folder. They are coming from different directories.

To avoid filename collision, could you advise me how to backup and preserve the directory structure?

C. H.
# 2  
This is probably the easiest:

find . -name "*.tar" | while read f
    td=/media/mypassport/backup/${f%/*}     # target directory  
    echo mkdir -p $td                       # remove echo to create and copy files
    echo cp $f  $td/

Assuming kshell or bash. Remove the 'echo' from each of the mkdir/cp command lines after you verify that the commands look good.
# 3  
Solution by creating file with a different name:-
for file in `find . -name "*.tar"`
        FNAME=`echo ${file} | awk -F"/" ' { print $NF } '`
        if [ -f /media/mypassport/backup/{FNAME} ]
                COUNTER=`expr ${COUNTER} + 1`
                FNAME=`echo ${FNAME} | sed 's/\.tar//g'`
                cp ${file} /media/mypassport/backup/${FNAME}_${COUNTER}.tar
                cp ${file} /media/mypassport/backup/${FNAME}

Last edited by Yoda; 10-20-2012 at 06:59 PM..
# 4  
find . -name '*.tar' | pax -rw /media/mypassport/backup

# 5  
Thank you for your advice. Forgive my ignorance:

Hi Alister,

1. What are the differences between par and cp? Was any compression applied?
2. Will the directory structure be preserved?
3. How about: find . -name '*.tar' | pax -w /media/mypassport/backup
4. Does it only work for *.tar files? How about *.jar or *.txt files?

C. H.

Previous Thread | Next Thread
Thread Tools Search this Thread
Search this Thread:
Advanced Search

Test Your Knowledge in Computers #720
Difficulty: Medium
Alan Minsky was an adviser on Stanley Kubrick's movie 2001: A Space Odyssey.
True or False?

8 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Backup script assistance - filename prompt

I am new to this forum, so please go easy on me :) I created a basic script to backup my router, which runs a linux firmware called OpenWrt. The script uses dd to image the router's RAM blocks, copy's the file to local usb storage, and then uploads it to a remote ISP personal ftp account. What I... (3 Replies)
Discussion started by: kgoerbig
3 Replies

2. Shell Programming and Scripting

rsync backup mode(--backup) Are there any options to remove backup folders on successful deployment?

Hi Everyone, we are running rsync with --backup mode, Are there any rsync options to remove backup folders on successful deployment? Thanks in adv. (0 Replies)
Discussion started by: MVEERA
0 Replies

3. UNIX and Linux Applications

2D collision simulation-programming

Hello, everybody, I'm thankful for the great helps you gave during the past year. Now I'm facing a serious problem: I was obliged to write a 2D collision simulation applet, and my experience is only in C,C++,Intelx86 assembly. I have no experience in Java and the like, and I don't know... (2 Replies)
Discussion started by: JackCrital2005
2 Replies

4. UNIX for Dummies Questions & Answers

Avoiding "file collision"

I don't know if there's a better name for what I call "file collision"... Basically, I have a script that I'm using for quick and dirty MySQL testing. Here's the idea... #!/usr/local/bin/bash for num in `jot $1` ## Yep, jot... this is FreeBSD do /usr/bin/time mysql --user=root... (2 Replies)
Discussion started by: treesloth
2 Replies

5. Shell Programming and Scripting

Filename from splitting files to have the same filename of the original file with counter value

Hi all, I have a list of xml file. I need to split the files to a different files when see the <ko> tag. The list of filename are B20090908.1100-20090908.1200_CDMA=1,NO=2,SITE=3.xml B20090908.1200-20090908.1300_CDMA=1,NO=2,SITE=3.xml B20090908.1300-20090908.1400_CDMA=1,NO=2,SITE=3.xml ... (3 Replies)
Discussion started by: natalie23
3 Replies

6. Infrastructure Monitoring

collision backoff algorithm

hi there, im new to this forum, so just like to day hello to everyone!!! i know im not aloud to post homework questions, but is it ok to ask for a formula to use to answer a question? i looking for a formula for collison backoff algorithm to find the average time to successfully transmit a... (3 Replies)
Discussion started by: purejoker
3 Replies

7. Shell Programming and Scripting

gzcat into awk and then change FILENAME and process new FILENAME

I am trying to write a script that prompts users for date and time, then process the gzip file into awk. During the ksh part of the script another file is created and needs to be processed with a different set of pattern matches then I need to combine the two in the end. I'm stuck at the part... (6 Replies)
Discussion started by: timj123
6 Replies

8. UNIX for Dummies Questions & Answers

access collision with shared file system

Hello ALL, In my system, there are 14 machines running the same version of Linux RHEL4. The 14 machines use a NFS file system, i.e., a shared file system. My question is that if the programs in individual machines can access a common file simutaneously. Or, they have to access the file... (1 Reply)
Discussion started by: cy163
1 Replies

Featured Tech Videos