Skip to content

Instantly share code, notes, and snippets.

@penn201500
Forked from enihsyou/backupRamDisk.sh
Created March 18, 2020 15:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save penn201500/4aa93f72c71ef0d45754e49cd669dd97 to your computer and use it in GitHub Desktop.
Save penn201500/4aa93f72c71ef0d45754e49cd669dd97 to your computer and use it in GitHub Desktop.
Create a RamDisk backup DMG image on macOS, detail in Chinese 中文: https://enihsyou.com/2019/02/04/48
#!/usr/bin/env bash
DISKNAME=${1-RAM}
IMAGE_LOCATION=${2-"/Users/enihsyou/Library/RAM.dmg"}
DISK_LOCATION=/Volumes/${DISKNAME}
sudo hdiutil create -srcfolder $DISK_LOCATION $IMAGE_LOCATION -ov
sudo chown enihsyou $IMAGE_LOCATION
#!/usr/bin/env bash
SIZE=${1-2048}
DISKNAME=${2-RAM}
BASE=/Volumes/$DISKNAME
[[ -e $BASE ]] && exit 0
DEVICE_IDENTIFIER=`diskutil info $DISKNAME | sed -n -E 's/^.*Device Identifier:.*(disk.*[0-9]).*/\1/p'`
if [[ -n $DEVICE_IDENTIFIER ]]; then
hdiutil mountvol $DEVICE_IDENTIFIER
exit 0
fi
DISK_ID=`hdiutil attach -nomount ram://$(( ${SIZE} * 1024 * 1024 / 512 ))` # a sector is 512 bytes
diskutil partitionDisk $DISK_ID GPT APFS "$DISKNAME" 0
# Backup location
IMAGE_LOCATION=${3-"/Users/enihsyou/Library/RAM.dmg"}
if [ -e $IMAGE_LOCATION ]; then
asr restore --source $IMAGE_LOCATION --target $BASE --erase --noverify --noprompt
else
cd $BASE
mkdir -p Cache/{Chrome,Firefox}
mkdir -p Compile/Hypers
mkdir -p Temp/{logs,HDFS/{namenode,datanode}}
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment