I was making bash script for game server, however the script doesn't work as I expect it to.
The idea of script is to make folder /ramdisk
then mount it as tmpfs
. Then copy files from /server/
that will be needed in /ramdisk
, backup game's worlds (that are store now in /ramdisk
), start server (which again is in /ramdisk
), when server shuts down copy files out of /ramdisk
back to /server
and then unmount ramdisk.
However the files aren't copied from /ramdisk
as expected... I believe that they don't copy at all, as all changes made in /ramdisk
aren't saved back to /server
directory, after the script finishes.
Also the script is saying that copying was successful and cp
does not give any error code.
Here is the script I am using:
echo Mounting RAMDISK...
if [ ! -d "/ramdisk" ]; then
echo Creating folder /ramdisk
mkdir /ramdisk
fi
mount -t tmpfs -o size=512M tmpfs /ramdisk
if [ $? -eq 0 ]; then
echo -e "Mounting RAMDISK... \033[0;32mFinished\033[1;37m"
else
echo -e "Mounting RAMDISK... \033[0;31mFAILED!!!\033[1;37m"
echo -e "\033[0;31mCritical Error\033[1;37m"
exit
fi
echo Copying files to RAMDISK...
cp -ar /server/* /ramdisk
if [ $? -eq 0 ]; then
echo -e "Copying files to RAMDISK... \033[0;32mFinished\033[1;37m"
else
echo -e "Copying files to RAMDISK... \033[0;31mFAILED!!!\033[1;37m"
echo -e "\033[0;31mCritical Error\033[1;37m"
exit
fi
tm=$(date "+%d-%m-%y_%H-%M-%S")
mkdir /server-backups/$tm-backup
echo Backing up World...
mkdir /server-backups/$tm-backup/world
cp -ar /ramdisk/world/* /server-backups/$tm-backup/world
if [ $? -eq 0 ]; then
echo -e "Backing up World... \033[0;32mFinished\033[1;37m"
else
echo -e "Backing up World... \033[0;31mFAILED!!!\033[1;37m"
fi
echo Backing up Nether...
mkdir /server-backups/$tm-backup/world_nether
cp -ar /ramdisk/world_nether/* /server-backups/$tm-backup/world_nether
if [ $? -eq 0 ]; then
echo -e "Backing up Nether... \033[0;32mFinished\033[1;37m"
else
echo -e "Backing up Nether... \033[0s;31mFAILED!!!\033[1;37m"
fi
echo Backing up End...
mkdir /server-backups/$tm-backup/world_the_end
cp -ar /ramdisk/world_the_end/* /server-backups/$tm-backup/world_the_end
if [ $? -eq 0 ]; then
echo -e "Backing up End... \033[0;32mFinished\033[1;37m"
else
echo -e "Backing up End... \033[0;31mFAILED!!!\033[1;37m"
fi
java -Xms2G -Xmx2G -jar /ramdisk/bukkit.jar -o false
#The error appears to be here
echo Copying files out of RAMDISK...
cp -ar /ramdisk/* /server
if [ $? -eq 0 ]; then
echo -e "Copying files out of RAMDISK... \033[0;32mFinished\033[1;37m"
else
echo -e "Copying files out of RAMDISK... \033[0;31mFAILED!!!\033[1;37m"
echo -e "\033[0;31mCritical Error\033[1;37m"
exit
fi
#End of error block
echo Unmounting RAMDISK...
umount /ramdisk
if [ $? -eq 0 ]; then
echo -e "Unmounting RAMDISK... \033[0;32mFinished\033[1;37m"
else
echo -e "Unmounting RAMDISK... \033[0;31mFAILED!!!\033[1;37m"
fi
This script was written by myself, and I admit that I haven't made much bash scripts in my life. I will be very happy if someone would be able to help me with this.
/ramdisk
and execute everything from hard drive, everything goes fine. I want however to use ramdisk as my hard drive is very slow and it has impact on game server