'Unable to Copy data from POD to local using kubectl cp command

I need to copy dump data from pod to local. Below the commands I am trying but I am getting error: unexpected EOF

kubectl cp device-database-79fc964c8-q7ncc:tmp /Users/raja
error: unexpected EOF

or

kubectl cp device-database-79fc964c8-q7ncc:tmp/plsql_data/prod.dump /Users/raja/prod.dump
error: unexpected EOF


kubectl version

kubectl version --client
Client Version: version.Info{Major:"1", Minor:"21", GitVersion:"v1.21.0", GitCommit:"cb303e613a121a29364f75cc67d3d580833a7479", GitTreeState:"clean", BuildDate:"2021-04-08T16:31:21Z", GoVersion:"go1.16.1", Compiler:"gc", Platform:"darwin/amd64"}

Can anyone help how to fix this issue?

Thanks



Solution 1:[1]

Using a "cat" command, rather than "cp" worked for me -- but only after 3 attempts.

The "cp" command failed over and over to get the whole file.

This "cat" style command did better each time.

So try this and see if your odds improve!

kubectl exec -i [pod name] -c [container name] -- cat [path to file] > [output file]

Solution 2:[2]

Could you move your db dump to a separate directory and then try to copy the entire directory ?

This may look like this:

kubectl cp device-database-79fc964c8-q7ncc:tmp/plsql_data/directory_containing_prod_dump /Users/raja/new_local_dir_containing_db_dump

According to this comment it may help.

It was also confirmed in comments by Bageshwar Pratap Narain and ?brahim ULUDA? that this solution worked for them.

Solution 3:[3]

For newer versions of kubectl, adding a retries=-1 flag may resolve the issue:

kubectl cp --retries=-1 pod-www-xxx-yyy-zzz:/path/to/remote/dir ~/local/dir 

Solution 4:[4]

In my case. Copying folder didn't helped. Instead tar.gz helps

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 warrens
Solution 2 mario
Solution 3
Solution 4 Suresh Ganesan