How to copy the whole folder using rsync ?


I'm now using the following command :

rsync --verbose --rsh='ssh -p6298' IP:/backup/cpbackup/daily/*.tar.gz /backup/cpbackup/daily/

But this will only copy the *.tar.gz , may i know how to make the command to copy the whole IP:/backup/cpbackup/daily/ folder including files and folders ?

Thank you.
Shamsul KamalJunior TechAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

rsync -av --rsh='ssh -p6298' IP:/backup/cpbackup/daily/*  /backup/cpbackup/daily/

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Hedley PhillipsOwnerCommented:
Drop the * off the end as when you terminate the source with / it will sync everything under that path


rsync -av --rsh='ssh -p6298' IP:/backup/cpbackup/daily/  /backup/cpbackup/daily/

whereas (note no slash after daily on the source)

rsync -av --rsh='ssh -p6298' IP:/backup/cpbackup/daily /backup/cpbackup/daily/

will copy the daily directory (and contents) from the source into the target and you would end up with:


As an additional note. If you want to exclude files or directories, use this:

rsync -avp --delete --exclude-from=exclude_file.txt

where exclude_file.txt has the format:

- *.txt
- *.doc
- */DIV*/*

The example above would exclude all .txt files, all .doc files and any directories under /div
Don't forget z flag, to compress tranferred contents, or it will take ages
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

Hedley PhillipsOwnerCommented:
While the -z switch can help, be careful where you use it.

With data that is already compressed, ie .zips or .gz's you could just be wasting CPU cycles and time and possibly even increasing the amount of data transferred.
Additionally, using the -z flag to transfer files across a gigabit link is wasteful and potentially slows the transfer down.
Of course, transferring already compressed files with compression in useless.
But I belive that saving transfer time is always a good thing.
Why on gigabit should it be wasteful?
Compression of data requires time and CPU cycles.  On fast links, depending on the type of data, it can often be faster to not use compression.
But doesn't this contribute to the general internet lag? Shouldn't we always try to send as little data as possible on a link?
If you have a link with plenty of capacity and you want to reduce transfer times and server load, then there's nothing wrong with uncompressed data.

Of course, it depends on many factors as to how beneficial or otherwise it will be.
I understand
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Shell Scripting

From novice to tech pro — start learning today.