Ramdisk backup & restore on MacOS X Lion

rd-backup.sh:

#!/bin/sh

mount |grep /Volumes/RamDisk > /dev/null
if [ $? -eq 0 ]; then
    echo saving /Volumes/RamDisk in /var/spool/rdimage
    sudo rsync -av --delete /Volumes/RamDisk/ /var/spool/rdimage/
    sudo diskutil unmount /Volumes/RamDisk
fi

rd-restore.sh:

#!/bin/sh

mount |grep /Volumes/RamDisk > /dev/null
if [ $? -ne 0 ]; then
    # 2GB
    sudo diskutil erasevolume HFS+ "RamDisk" `hdiutil attach -owners on -nomount ram://4194304`
    sudo diskutil enableOwnership /Volumes/RamDisk

    #restore ramdisk image from disk
    sudo rsync -a /var/spool/rdimage/ /Volumes/RamDisk/
fi

And use it as a temporary area in Xcode etc.

Leave a Reply

Your email address will not be published. Required fields are marked *