<h1>Where I started / The problem.</h1>
<p>I am trying to run a fairly complex kubectl command to copy files above a specific date from kubernetes to a local drive.</p>
<p>I am trying to take advantage of this command.
<code>$ kubectl cp &lt;file-spec-src&gt; &lt;file-spec-dest&gt;</code></p>
<p>Which according to <a href="https://kubernetes.io/docs/reference/generated/kubectl/kubectl-commands#cp" rel="nofollow noreferrer">https://kubernetes.io/docs/reference/generated/kubectl/kubectl-commands#cp</a>
Is a &quot;shorthand&quot; for this command.
<code>kubectl exec -n &lt;some-namespace&gt; &lt;some-pod&gt; -- tar cf - /tmp/foo | tar xf - -C /tmp/bar</code></p>
<p>Which works but had not date restriction parameters.</p>
<h1>What commands I came up with (which didn't work).</h1>
<p>However, I do not just want to copy files, I want to copy specific files. In that pursuit I come up with 2 commands that both work on my local machine, but not when used with kubectl.</p>
<h2>Command 1</h2>
<p>My thought with command 1 was just to find a solution to the date problem first, then get it to tar, and the out of tar. Pipes seemed appreciate until I got to the kubectl command.</p>
<h2>Command 1 local.</h2>
<p><code>find /foo -type d -maxdepth 3 -newermt '2/25/2021 0:00:00' -print0 | xargs -0 tar cf - | tar xf - -C /bar</code></p>
<h2>Command 1 kubectl.</h2>
<p><code>kubectl exec -n &lt;namespace&gt; &lt;pod_name&gt; -- &quot;find /foo -type d -maxdepth 3 -newermt '2/25/2021 0:00:00' -print0 | xargs -0 tar cf - &quot; | tar xf - -C /bar</code></p>
<p>The quotations (&quot;&quot;) around find and the first pipe is there because those need to be run in the kubernetes pod. The last pipe is there as in the official command, to pipe to local disk.</p>
<h3>Error</h3>
<p>The command only returns an error, and not a useful one at that. What I can say is that removing the last pipe returns the same error.
<code>no such file or directory: unknown</code></p>
<h2>Command 2</h2>
<p>My thought behind command 2, was that if pipes creates too many problems for me, why not take advantage of find´s -exec command, and only have 1 pipe.</p>
<h2>Command 2 local.</h2>
<p><code>find /foo -type d -maxdepth 3 -newermt '2/25/2021 0:00:00' -exec tar -rvf - {} \; | tar xf - -C /bar</code></p>
<h2>Command 2 kubectl.</h2>
<p>kubectl exec -n  &lt;pod_name&gt; -- find /foo -type d -maxdepth 3 -newermt '4/1/2021 0:00:00' -exec tar -cf - {} ; | tar xf - -C /bar</p>
<h2>Error</h2>
<p>The command does this time, not return an error, but instead proceeds to copy every file it can find, even those outside of the &quot;-type&quot; &quot;-maxdepth&quot; &quot;-newermt&quot; parameters. So this command essentially does that same as just copying the entire folder.</p>
<h1>Finally</h1>
<p>I have no clue as to how to proceed from here. Is there any other combination that I could try, or is there some sort of error in my code anyone could help me with ?</p>
<p>Thanks :)</p>

Photic
<p>For now I am running it with a compromise that works.</p>
<p><code>kubectl exec -n &lt;namespace&gt; &lt;pod_name&gt; -- find /foo -type f -newermt '4/1/2021 0:00:00' -exec tar -cf - {} + | tar xf - -C ./bar --strip-components=3</code></p>
<p>This how ever takes longer to run since I look at every file, and not just the top level folders.</p>
