[solved] copying files and preserving directory structure (unix)

Discussion in 'Mac Programming' started by zimv20, Jun 11, 2007.

  1. zimv20 macrumors 601

    zimv20

    Joined:
    Jul 18, 2002
    Location:
    toronto
    #1
    first, let me describe the problem:

    i want to back up all my .ptf (pro tools session) and .rtf (record and mix notes) files to .mac. Because my music folder (w/ all its many subfolders) contains big audio files, i can't just tell Backup to start at /music.

    so what i thought i'd do is write a Bourne shell script to create a parallel directory structure, with only the .ptf and .rtf files, and Backup that. i need to preserve the directory structure, because not all the .rtf files have unique names. then i'd use cron to schedule the script to run once/day.

    i've got the script all written, BUT the cp command doesn't behave as i remember it behaving "back in the day".

    i had (mis)remembered that this command:

    % cp -Rp /foo/bar/baz/foo.txt ./bak

    ... would create ./bak/foo/bar/baz. but unless i omit foo.txt from the command, it doesn't. did it used to work that way? who knows, but it's not doing that now.

    SO...

    i need to find a workaround. not all directories have .ptf and .rtf files in them, so i don't want to replicate irrelevant directories in the backup hierarchy. also, i create new directories every few days, so i don't want to have to remember to also create them in the backup hierarchy. i.e. the script should pick those up automagically.

    here's the magic command i have so far, but the result is all the files are copied into a single directory, specified by $DESTDIR:
    Code:
    % find . \( -name "*.ptf" -or -name "*.rtf" \) \! -path "*/Session\ File\ Backups/*" -exec cp -Rp {} $DESTDIR \;
    
    (note: i'm ignoring files in any subdir called "Session File Backups")

    i've also tried stuff along the lines of:
    Code:
    % find . -name "*.ptf" -print | xargs -I '{}' cp -Rp {} $DESTDIR
    
    ... but of course that's not working either. sadly, even if the destination hierarchy exists, i've discovered, the -Rp option doesn't drop the files in the right spot. they go in $DESTDIR and that's that.

    i'm thinking something along the lines of find's -prune to grab the directory, and appending that to $DESTDIR, but i can't quite get it sussed out.

    i'm embarrassingly stumped. maybe i should write it in nawk. hmmm....

    any ideas?
     
  2. balamw Moderator

    balamw

    Staff Member

    Joined:
    Aug 16, 2005
    Location:
    New England
    #2
    How about something like

    Code:
    zip -r $SOURCEDIR -i *.[pr]tf $DESTZIP
    and backup the zip file?

    B
     
  3. zimv20 thread starter macrumors 601

    zimv20

    Joined:
    Jul 18, 2002
    Location:
    toronto
    #3
    hey, i like the *.[pr]tf bit, nice touch.

    figures that as soon as i post a long, detailed question i'll figure something out on my own. i discovered the pax command, and it does what i need. the magic command is now:
    Code:
    % find . -name "*.[pr]tf" \! -path "*/Session\ File\ Backups/*" -exec pax -rw {} $DESTDIR \; 
    
    thanks!
     

Share This Page