Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- ## SYNOPSIS ##
- #
- # Based on http://wiki.natenom.name/mumble/tools/mumble-db-tmpfs
- #
- # This scripts copies your mumble database and log from a backup directory into a tmpfs and dumps them with unmount
- # switching between two ini files so mumble could run from ram and from sd as well.
- # I decided to put the log file too in the ram disk because the life span of a SD card is severely related to the write cycles.
- # You can run this script on boot/shutdown (google a bit to know how)
- #
- # Run this script as a SuperUser
- #
- # A big thank to Natenom!
- ## PREPARATION ##
- #
- # Make a directory where tmpfs will be mounted (i.e. /var/tmp/ or /home/pi/tmpfs/)
- #
- # In /etc/ make two copies of your mumble-server.ini named mumble-server.ram and mumble-server.sd
- # in the first one you have to replace the path in "database=" and "logfile=" with your tmpfs directory
- # in the second one set your backup directory path
- #
- # Now copy your database and log files in the backup directory (you can find their location in the original .ini file)
- #
- # It's good if you make a backup of mumble-server.ini and mumble-server.sqlite
- _tmpfs_dir="[tmpfs location]" # Must be the same as database="[path of file] and logfile=[path of file] in mumble-server.ram
- _database_backup_dir="[backup location]" # The same path as in mumble-server.sd
- _mumble_ini_dir="/etc" # *.ini file location. /etc by default
- _owner="mumble-server" # Name of the user the mumble-server runs as (to set file permissions), you can get it from mumble-server.ini
- case $1 in
- start)
- if [ "$(mount | grep ${_tmpfs_dir})" != "" ]; then # Checking if _tmpfs_dir is already mounted... you have to use an empty ramdisk, this script may unmount
- echo "tmpfs partition already exists. Script halted." # the partition causing data loss if other process uses the same tmpfs!
- else
- echo "${_tmpfs_dir} is not mounted. Mounting..."
- mount tmpfs -t tmpfs "${_tmpfs_dir}" # Mounting tmpfs in _tmpfs_dir
- #if you use debian < 6.x, remove -n
- cp ${_mumble_ini_dir}/mumble-server.ram ${_mumble_ini_dir}/mumble-server.ini # Using mumble-server.ram as *.ini file
- cp -n ${_database_backup_dir}/mumble-server.sqlite ${_tmpfs_dir}/ # Putting database and logfile in the tmpfs
- cp -n ${_database_backup_dir}/mumble-server.log ${_tmpfs_dir}/
- chown ${_owner} ${_tmpfs_dir}/mumble-server.sqlite # Fixing permissions
- chgrp ${_owner} ${_tmpfs_dir}/mumble-server.sqlite
- chown ${_owner} ${_tmpfs_dir}/mumble-server.log
- chgrp ${_owner} ${_tmpfs_dir}/mumble-server.log
- /etc/init.d/mumble-server restart # Mumble server restart
- echo "Mumble server is up, database running from ram."
- fi
- ;;
- stop)
- if [ "$(mount | grep ${_tmpfs_dir})" != "" ]; then
- cp ${_tmpfs_dir}/mumble-server.sqlite ${_database_backup_dir}/ # Dumping database and logfile to disk
- cp ${_tmpfs_dir}/mumble-server.log ${_database_backup_dir}/
- chown ${_owner} ${_database_backup_dir}/mumble-server.sqlite # Fixing permissions
- chgrp ${_owner} ${_database_backup_dir}/mumble-server.sqlite
- chown ${_owner} ${_database_backup_dir}/mumble-server.log
- chgrp ${_owner} ${_database_backup_dir}/mumble-server.log
- /etc/init.d/mumble-server stop # Shutting down mumble server
- cp ${_mumble_ini_dir}/mumble-server.sd ${_mumble_ini_dir}/mumble-server.ini # Using mumble-server.sd as *.ini file
- # so if you run mumble now it'll works (slowly)
- umount "${_tmpfs_dir}" # Unmounting tmpfs
- echo "Mumble server halted and tmpfs unmounted."
- echo "You can now reboot your system safely or restart mumble-server from sd"
- else
- echo "${_tmpfs_dir} is not mounted."
- fi
- ;;
- *)
- echo "$0 start|stop"
- ;;
- esac
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement