Skip to content

Instantly share code, notes, and snippets.

@AndreSteenveld
Created November 30, 2017 12:01
Show Gist options
  • Save AndreSteenveld/c9b519a7b755645bb1861166785f6684 to your computer and use it in GitHub Desktop.
Save AndreSteenveld/c9b519a7b755645bb1861166785f6684 to your computer and use it in GitHub Desktop.
Poor man's COW
#!/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"
@AndreSteenveld
Copy link
Author

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 install bindfs, rsync and coreutils before running this. ($ brew install bindfs rsync coreutils)

Usage: $ ./poor-cow.sh ./source-directory/ ./target-directory/ ./overlay-directory/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment