Copy ./ to subdirectory.

This is probably a simple question but I can't find the answer
anywhere and my friend Google won't search for ./ and 'copy' brings up
all sorts.

Basically, I've got a folder containing various files for a website
(for simplicity lets say it's this):

/mydirectory/index.html
/mydirectory/images/image.gif

I want to make a backup so in the /mydirectory/ folder I do:

cp -r ./ backup

I wanted his to result in:

/mydirectory/index.html
/mydirectory/images/image.gif
/mydirectory/backup/index.html
/mydirectory/backup/images/image.gif

Does that make sense? The error I get is:

cp: cannot copy a directory, `./', into itself, `backup'

Is there a way to have cp ignore the newly created directory? Something like:

cp -r ./ backup --ignore=backup

Any help appreciated. I can work around it by simply making my backup
somewhere else but I would be suprised if it's not possible to do this
somehow.

Kind Regards and many thanks,

James

--

0

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

Copy ./ to subdirectory.

On Wed, Aug 29, 2007 at 01:16:50PM +0100, James Preece wrote:
> Basically, I've got a folder containing various files for a website
> (for simplicity lets say it's this):
>
> /mydirectory/index.html /mydirectory/images/image.gif
>
> I want to make a backup so in the /mydirectory/ folder I do:
>
> cp -r ./ backup
>
> I wanted his to result in:
>
> /mydirectory/index.html /mydirectory/images/image.gif
> /mydirectory/backup/index.html /mydirectory/backup/images/image.gif
>
> Does that make sense? The error I get is:
>
> cp: cannot copy a directory, `./', into itself, `backup'
>
> Is there a way to have cp ignore the newly created directory?
> Something like:

Unfortuntly, Debian relies on GNU and GNU has changed the licence on the
docs to be incompatible with Debian. Notice that the stub of a man
pages directs you to info cp, however info cp gives you cpio instead.
OOPS.

try:
$ mkdir backup
$ cp -r i* backup/

I don't see anything like --ignore in the man page.

Personally, for stuff like that I use mc. If I'm writing a script, I'm
using Python anyway.

Doug.

--

Copy ./ to subdirectory.

On Wed, Aug 29, 2007 at 01:16:50PM +0100, James Preece wrote:
>
> cp: cannot copy a directory, `./', into itself, `backup'
>
> Is there a way to have cp ignore the newly created directory? Something like:
>
> cp -r ./ backup --ignore=backup
>

You could try using tar. Something like

tar --exclude=backup | tar -x --directory=backup

--

Patrick Ouellette
Amateur Radio: KB8PYM
Living life to a Jimmy Buffett soundtrack
"Crank the amp to 11, this needs more cowbell - and a llama wouldn't hurt either"

--

Copy ./ to subdirectory.

Mike Bird wrote:
> James Preece wrote:
> > cp -r ./ backup
>
> I'd use rsync locally.

+1 on rsync. It is the perfect tool for this task.

> First a dry-run in case I'd made a mistake:

Excellent advice. Follow the advice or suffer for it when a typo is
made! :-)

> rsync -a --delete --exclude=backup /mydirectory/ /mydirectory/backup/
> ...
> Please note that trailing slashes on directory names are significant
> to rsync.

That is another important point. If the source includes a trailing
slash then it means that directory. Plus on other systems such as
HP-UX in particular there are bugs which cause this to behave
differently than it should. I have found that specifying the
source directory into the destination directory above with a trailing
slash to be most portable.

rsync -avn sourcedir destdir/

This results in:

destdir/sourcedir

Bob

--

Copy ./ to subdirectory.

Hi,

On Wed, Aug 29, 2007 at 01:16:50PM +0100, James Preece wrote:
> This is probably a simple question but I can't find the answer
> anywhere and my friend Google won't search for ./ and 'copy' brings up
> all sorts.
>
> Basically, I've got a folder containing various files for a website
> (for simplicity lets say it's this):
>
> /mydirectory/index.html
> /mydirectory/images/image.gif
>
> I want to make a backup so in the /mydirectory/ folder I do:
>
> cp -r ./ backup
>
> I wanted his to result in:
>
> /mydirectory/index.html
> /mydirectory/images/image.gif
> /mydirectory/backup/index.html
> /mydirectory/backup/images/image.gif
>
> Does that make sense? The error I get is:
>
> cp: cannot copy a directory, `./', into itself, `backup'
>
> Is there a way to have cp ignore the newly created directory? Something like:
>
> cp -r ./ backup --ignore=backup
>
> Any help appreciated. I can work around it by simply making my backup
> somewhere else but I would be suprised if it's not possible to do this
> somehow.

I think direct answer to your question has been answered :-)

Here is the twisted one for back up.

The way you do only gives you single level backup. Please consider
making use of git (git-core package). Then you get nice history with
gui (gitk).

http://wiki.debian.org/DRData?action=show#head-386c7f05861f6cebf5eae046652c2ac25a8f1ddf

If you are making timed backup with plain cp, you can do it with find
while using prune to avoid stepping on your own backup.

http://localhost/Wiki/DRData?action=show#head-386c7f05861f6cebf5eae046652c2ac25a8f1ddf

> Kind Regards and many thanks,

God luck.

--

Syndicate content