Last active
May 17, 2022 18:12
-
-
Save redguardtoo/596b1a9fd3eac1cedd13 to your computer and use it in GitHub Desktop.
script to copy project to tmpfs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
不错