1

I have taken a backup of a large directory onto a mounted external disk, using rsync -av. The command terminated after sometime, but after that I am unable to unmount the disk, when I try to unmount I get the error disk is busy, try after some time.

Is the data been cached up and the copying is still in progress? How can I know when the copying is finally done and I can unmount?

Or, is there a better way to take a backup of a large directory?

(This is on ubuntu 20.04)

Raffles
  • 768
R71
  • 131
  • Have you read the community wiki? There is a GUI called Grsync as well. https://help.ubuntu.com/community/rsync – Raffles May 19 '21 at 17:31
  • There is also Timeshift, see this topic >>> https://askubuntu.com/questions/1119961/why-is-timeshift-not-on-the-official-ubuntu-repos – Raffles May 19 '21 at 18:06
  • 1
    I would use unison-gtk or rsnapshot depending if it's one-off or a regular backup. (Timeshift focuses on system-level directories; rsnapshot is really for home directories, etc.) As for finding out why it's busy, type sudo lsof <path> and it will tell you what is still using it. If you have some terminal still in that directory, that's enough to prevent unmounting. – Ray May 20 '21 at 04:13

1 Answers1

0

Maybe you can't unmount the device because rsync does not use direct I/O (O_DIRECT) while writing. So it's not:

rsync > device

Instead it is:

rsync > RAM > device

And after rsync has finished its work, the Linux Kernels (sometimes) needs time to copy the page cache to the device and as long this isn't finished, you probably can not unmount it.

You have some options to solve this:

  1. Mount your device with direct i/o, but this will probably cause a bad performance
  2. Use sync before umount
  3. Use umount -l which removes the mount path from the filesystem, but it is still present for the Kernel to finish its work and after this is done, the mount is finally removed, so why this is called a lazy unmount. But this is considered as bad practice.
mgutt
  • 160
  • 6