Skip to content

Instantly share code, notes, and snippets.

@robertoestivill
Last active May 8, 2020 10:26
Show Gist options
  • Save robertoestivill/c48e8061c1bda80e39c1119daba6486c to your computer and use it in GitHub Desktop.
Save robertoestivill/c48e8061c1bda80e39c1119daba6486c to your computer and use it in GitHub Desktop.
RAM disk + rsync
###############
# Step 0:
# Disclaimer
#
# RAM DISK ARE VOLATILE. YOU WILL LOOSE DATA IF POWER IS INTERRUPTED.
#
###############
# Step 1:
# Create ram disk with specified capacity
#
# https://bogner.sh/2012/12/os-x-create-a-ram-disk-the-easy-way/
#
# The size of the disk is based on the page size number of 512 bytes sectors. That means the size in bytes has to be divided by 512.
# For example to calculate the size parameter for a volume with 4GiB the following formular is used:
# ( 4 * (1024^3) ) / 512 = 8388608 (4gb)
#
$ diskutil erasevolume HFS+ 'myramdisk' `hdiutil attach -nomount ram://8388608`
###############
# Step 2:
# Copy original project to ram disk
#
$ cp -R ./myproject /Volumes/myramdisk/
#
# or with rsync
#
$ rsync -a ./myproject /Volumes/myramdisk/
###############
# Step 3:
# Keep original copt up to date with rsync in a terminal
#
# https://stackoverflow.com/questions/12460279/how-to-keep-two-folders-automatically-synchronized
#
#
# With filesystem events
#
# ONLY LINUX
$ while inotifywait -r -e modify,create,delete,move /Volumes/myramdisk/myproject; do
rsync -avz /Volumes/myramdisk/myproject ./myproject
done
#
# or with timer for MacOSx
#
$ while true; do
rsync -av --delete /Volumes/myramdisk/myproject ./myproject
sleep 10 # seconds
done
###############
# Step 4:
# Point your IDE/tools to the copy in the RAM disk
#
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment