Detecting If a Directory Is Mounted or Not (Useful for Backup Scripts)
In this video, we'll use the mountpoint command to check if a directory is mounted and improve a backup script to use it.
Quick Jump:
A few years ago I wrote a blog post on how to do offline backups with Bash and rsync.
In this video, we’ll use the mountpoint
command to make this script better so
you don’t accidentally backup your files to the wrong drive due to thinking
your external drive is mounted when it’s really not.
# Demo Video
Timestamps
- 0:59 – Getting a list of mounts on your system with
mount -l
- 2:06 – Using the
mountpoint
command to check if a path is mounted - 2:52 – Adjusting a backup script to check for a mounted backup target
Reference Links
- https://nickjanetakis.com/blog/3-gotchas-with-wsl-2-around-disk-space-memory-usage-and-performance
- https://nickjanetakis.com/blog/automatic-offline-file-backups-with-bash-and-rsync
What are you going to use this command for? Let me know below.