On Wednesday 29 August 2007 05:16, 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'd use rsync locally.  First a dry-run in case I'd made a mistake:

rsync --dry-run -va --delete --exclude=backup /mydirectory/ /mydirectory/backup/

And then remove --dry-run and maybe also -v for the production version:

rsync -a --delete --exclude=backup /mydirectory/ /mydirectory/backup/

For more complicated cases I'd add the -H and -S flags but it doesn't
look like they're needed here.

Please note that trailing slashes on directory names are significant to rsync.
If you change the examples above you may see different behavior.

--Mike Bird


-- 
To UNSUBSCRIBE, email to [EMAIL PROTECTED] 
with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]

Reply via email to