Operating System - HP-UX
1753756 Members
4759 Online
108799 Solutions
New Discussion юеВ

Re: scp command to exclude particular directory

 
SOLVED
Go to solution
HP-UX_Ali
Regular Advisor

scp command to exclude particular directory

Hi All,

Please adivce, i have to copy all directories & files under directory to remote server but wanna exclude 1 directory.

kindly confirm the scp command option.

else i am thinking of making 1 server as nfs & mount the fs & then start copy with cp.
but cp too doesnt have exclude option .

rsync is having but --exclude doest recognize the PATTERN directory name.

can any confirm the correct command & syntax.
for exclude sigle directory....

17 REPLIES 17
Raj D.
Honored Contributor

Re: scp command to exclude particular directory

ALI,
scp do not have any include exclude option and that is why rsync can be use.

> rsync is having but --exclude doest recognize the PATTERN directory name.

What patern you are trying. To exclude any directory you can use the --exclude option with rsync.

You have to the exclude option with double quote that will match the regex. Also you must put the / in the directory you want to exclude:


Ex:

# rsync -avz --exclude=sapr1/ --exclude=saparch1/ source_host:/data/ target_host:/data/


Hth,
Raj.


" If u think u can , If u think u cannot , - You are always Right . "
Raj D.
Honored Contributor

Re: scp command to exclude particular directory

Also check this out:
http://lists.samba.org/archive/rsync/2002-June/002970.html

" If u think u can , If u think u cannot , - You are always Right . "
John Guster
Trusted Contributor

Re: scp command to exclude particular directory

Normally one does in this situation is to make a tar of that directory, scp it over, untar it, then you can remove that one directory one doesn't want. Hope help.
Dennis Handly
Acclaimed Contributor

Re: scp command to exclude particular directory

>John: make a tar of that directory

Or use pax(1) or gnu tar and exclude that directory when you create the tarfile (or when you extract.)
Steve Post
Trusted Contributor

Re: scp command to exclude particular directory

What I do....

I have boxA
I want to copy over boxA:/opt/stuff to boxB:/mydir/stuff
I want to exclude subdirectory /opt/stuff/racerX
I want to exclude any file with the word BLUE in them.

on boxA
cd /opt
find ./stuff -print > /tmp/stufflist.txt
cd /tmp
edit text file ./stufflist.txt
remove subdirectory ./stuff/racerX
remove any lines with BLUE in them
save the file

Log into box B
cd to mydir
Just sit there.

Go back to box A.
--Now here comes the magic part--

cat ./stufflist.txt | cpio -odumc | /usr/bin/ssh \
-2 \
mylogin@boxB \
"cd /mydir/.
/usr/bin/cpio -idumc"



BUT! be careful. I'd start with just 2 or 3 files and directories.
SMALL ones.
Make sure it works.
Then move to larger things.


Now other guys... This has worked fine for me. But perhaps there is something wrong? Let me know.

Oh...
The find command will not follow links unless you tell it to. And I would NOT tell it to.

Tingli
Esteemed Contributor

Re: scp command to exclude particular directory

You can use this:

scp -r $(ls | -e /directory_not_to_copy/d) remote:
Tingli
Esteemed Contributor

Re: scp command to exclude particular directory

Sorry, I missed something.

scp -r $(ls | sed /directory_not_to_copy/d) remote:
Raj D.
Honored Contributor
Solution

Re: scp command to exclude particular directory

Ali, you can also use grep similarly to exclude multiple directory:

# scp -r $(ls | grep -v -e dir_to_exclude1 -e dir_to_exclude2 ) trg_host:/trg_dir/


Hth,
Raj.




" If u think u can , If u think u cannot , - You are always Right . "
Steve Post
Trusted Contributor

Re: scp command to exclude particular directory

So I guess this means you can do this

find /stuff > filelist.txt

vi filelist.txt

scp -r $( cat filelist.txt ) trg_host:/trg_dir/