Last active
December 30, 2019 14:45
-
-
Save dvdcastro/0e300cf7fa45b99832bc9f11c407c6b6 to your computer and use it in GitHub Desktop.
Moves mysql to a ram disk on Ubuntu 18.04 - Use at your own risk, information on ram is volatile
This file contains hidden or 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/bash | |
service mysql stop | |
echo "Stopped mysql." | |
umount /mnt/ramdisk | |
echo "Unmounted ramdisk /mnt/ramdisk" | |
mkdir -p /mnt/ramdisk | |
mount -t tmpfs -o size=2048m tmpfs /mnt/ramdisk | |
echo "Mounted ramdisk /mnt/ramdisk" | |
if [ ! -d "/var/lib/mysql.bk" ] | |
then | |
mv /var/lib/mysql /var/lib/mysql.bk | |
echo "Moved mysql library folder to backup folder." | |
fi | |
cp -rp /var/lib/mysql.bk /mnt/ramdisk/mysql | |
echo "Copied mysql backup to ramdisk." | |
if [ -L /var/lib/mysql ] && [ -e /var/lib/mysql ] | |
then | |
rm /var/lib/mysql | |
echo "Removed symlink /var/lib/mysql." | |
fi | |
ln -s /mnt/ramdisk/mysql /var/lib | |
echo "Recreated symlink /var/lib/mysql." | |
if ! grep -q "alias /var/lib/mysql/ -> /mnt/ramdisk/mysql," "/etc/apparmor.d/tunables/alias" | |
then | |
echo "alias /var/lib/mysql/ -> /mnt/ramdisk/mysql," >> /etc/apparmor.d/tunables/alias | |
echo "Appended alias to apparmor." | |
systemctl restart apparmor | |
echo "Restarted apparmor." | |
fi | |
service mysql start | |
echo "Started mysql." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
To have everything back as it was: