0

I have a very large file (>100GB) on one volume mount in a Docker container. I would like to move it to another volume mount in the same container. However, when I do so using rename, I get the following error: invalid cross-device link. The code I'm using to do this is the following:

            fmt.Printf("Moving %s to %s\n", oo, outputPath)
            err = fs.Rename(oo, strings.Replace(oo, inputPath, outputPath, 1))
            if err != nil {
                fmt.Printf("Error moving %s to %s: %v", oo, outputPath, err)
                return
            }

I understand why, but what's my alternative? Copying and deleting is really not an option with a file this big. Is there a better way to move across two volumes in a more space efficient way?

The good news is that they’re on the same disk in the underlying container. But the container is extremely locked down, so issuing underlying server commands would not be possible/really hard. That said, we COULD potentially mount them as a unified volume - interesting idea. Is it possible to mount two separate root directives as the same volume?

aronchick
  • 6,786
  • 9
  • 48
  • 75
  • If the volume mount points sit atop an underlying unified file system to which some *other* system (perhaps one outside this docker container) has access, you can use a rename operation there. If it's completely outside your docker instance, consider pretending that your docker instance is a client, and this is a server on a separate machine: you send a rename request to the server, which vets it for permission etc and then performs it as a service. – torek Oct 12 '22 at 04:30
  • To avoid this kind of external-server overhead, consider mounting the shared underlying volume in the container as a single volume, which of course eliminates the original problem entirely. But presumably you would have already done that, if it were that simple. Perhaps you can provide *three* mount points, two separate ones for the system that insists on using two separate volumes, and one unified whole-volume mount point. – torek Oct 12 '22 at 04:34
  • 3
    (Note that in the end, this is a Docker and OS issue, not a Go issue. You're just seeing it expressed in the Go runtime.) – torek Oct 12 '22 at 04:35
  • Yeah it makes total sense this is an OS issue, I just didn’t know if there was a Go specific way around it – aronchick Oct 12 '22 at 13:44
  • So the good news is that they’re on the same disk in the underlying container. But the container is extremely locked down, so issuing underlying server commands would not be possible/really hard. That said, we COULD potentially mount them as a unified volume - interesting idea. Is it possible to mount two separate root directives as the same volume? – aronchick Oct 12 '22 at 13:46
  • 1
    I don't *think* you can do that, but Docker surprises me sometimes... – torek Oct 12 '22 at 18:57

0 Answers0