Created
November 30, 2017 12:01
-
-
Save AndreSteenveld/c9b519a7b755645bb1861166785f6684 to your computer and use it in GitHub Desktop.
Poor man's COW
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Exit if something totally fails | |
set -e | |
source_directroy="$( readlink -e $1 )" | |
target_directory="$( readlink -e $2 )" | |
overlay_directory="$( readlink -e $3 )" | |
df --output=target | grep "$target_directory" | xargs -L1 umount -f | |
mount_point="$target_directory/.loopback" | |
mkdir -p $mount_point | |
rsync \ | |
--cvs-exclude \ | |
--verbose \ | |
--recursive \ | |
--hard-links \ | |
--link-dest="$source_directroy/" \ | |
"$source_directroy/" \ | |
"$target_directory/" | |
bindfs -o allow_recursion,noappledouble,noapplexattr,nobrowse,auto_cache,kill_on_unmount "$target_directory/" "$mount_point" | |
bindfs -o union,allow_recursion,noappledouble,noapplexattr,nobrowse,auto_cache,kill_on_unmount "$overlay_directory" "$target_directory" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This script has only been tested on OSX Sierra, for some reason mounting a directory on a nested mount point in your home directroy will hang-up
bindfs
. Make sure to installbindfs
,rsync
andcoreutils
before running this. ($ brew install bindfs rsync coreutils
)Usage:
$ ./poor-cow.sh ./source-directory/ ./target-directory/ ./overlay-directory/