Skip to content

Instantly share code, notes, and snippets.

@redguardtoo
Last active May 17, 2022 18:12
Show Gist options
  • Save redguardtoo/596b1a9fd3eac1cedd13 to your computer and use it in GitHub Desktop.
Save redguardtoo/596b1a9fd3eac1cedd13 to your computer and use it in GitHub Desktop.
script to copy project to tmpfs
#!/bin/sh
if [ -z "$1" ];then
echo "Usage:"
echo " proj2ram proj-name"
echo " proj2ram restore proj-name"
exit 1
fi
if [ "$1" != "restore" ];then
backup=$1-backup
link=$1
volatile=/tmp/$1-$USER
IFS=
set -efu
cd ~/projs
if [ ! -r $volatile ]; then
mkdir -m0700 $volatile
fi
# link -> volatie does not exist
if [ "$(readlink $link)" != "$volatile" ]; then
# backup project at first
mv $link $backup
# create the link
ln -s $volatile $link
fi
if [ -e $link/.unpacked ]; then
echo "Sync project from memory to backup ..."
rsync -avq --delete --exclude .unpacked ./$link/ ./$backup/
echo "DONE!"
else
echo "Sync project from disk to memory ..."
rsync -avq ./$backup/ ./$link/
touch $link/.unpacked
echo "DONE!"
fi
else
if [ -z "$2" ]; then
echo "Usage:"
echo " proj2ram restore proj-name"
else
echo "Moving project back to disk ..."
backup=$2-backup
link=$2
volatile=/tmp/$2-$USER
cd ~/projs
rm $link && mv $backup $link && rm -rf $volatile
echo "DONE!"
fi
fi
@Lujango
Copy link

Lujango commented Nov 24, 2016

不错

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