[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: General method for copying a partition



On 20100218_130038, Stephen Powell wrote:
> On Wed, 17 Feb 2010 15:04:32 -0500 (EST), Boyd Stephen Smith Jr. wrote:
> > On Wednesday 17 February 2010 13:40:20 Stephen Powell wrote:
> >> On Wed, 17 Feb 2010 12:26:43 -0500 (EST), Boyd Stephen Smith Jr. wrote:
> >>> Use this instead:
> >>> cp -a /media/. /mnt
> >>> OR
> >>> cp -a /media/{.[!.],}* /mnt
> >> 
> >> Your second method doesn't work in ash because ash does not support
> >> brace expansion.
> >
> > Sorry, I sometimes forget that brace expansion isn't part of the standard 
> > Shell Command Language.
> > 
> > You could write them out separately:
> > cp -a /media/.[!.]* /media/* /mnt
> > BUT
> > That could still fail depending on how your shell treats patterns that do not 
> > match any existing pathnames (standard behavior is to leave the pattern 
> > string, but both bash and zsh have options of different behavior) and how your 
> > cp utility handles source_file arguments that do not exist.
> 
> All valid points.  I'm going with
> 
>    cp -a /media/. /mnt
> 
> There will always be a "/media/." directory.  And although rsync is a nice
> tool, the specific application here is copying from one local filesystem
> to another local filesystem, the target having just been formatted with mkfs
> prior to mounting and is therefore totally empty.  Therefore, there is no
> "synchronization" needed.  "Copy everything" is the order of the day.
> Furthermore, rsync is not part of the standard system, nor is it available
> when using the Debian Installer in a rescue-like mode.  (Still, rsync is a
> nice tool to know about; and I'm glad that the posts concerning it were made.)
> 
> Thanks to all responders!  You've thought of several methods that I never would
> have thought of on my own.
> 

A small variant on this cp command would also be useful for a second, or later,
copying of /media onto the same device mounted on /mnt:

cp -a --backup=t /media/. /mnt

This will handle file name collisions in a useful way by appending .~n~ to
the file name on /mnt when a file with the same name is copied from /media.
(n is a number that is incremented each time the happens for a given name)

-- 
Paul E Condon           
pecondon@mesanetworks.net


Reply to: