#!/bin/bash
#This scripts copies your mumble database from a backup directory into a tmpfs and recovers it with unmount.

_tmpfs_dir="/home/mumble-server1/database-where-tmpfs-is-mounted/" #This path must be used for database= entry in your murmur.ini
_database_backup_dir="/home/mumble-server1/database_backup_directory/" #This directory must contain the xxx.sqlite before mounting _tmpfs_dir
_owner="murmur" #Name of the user the mumble-server runs as (to set file permissions)

case $1 in
  mount)
      if [ "$(mount | grep ${_tmpfs_dir})" != "" ]; then
          echo "Already mounted."
      else
          echo "${_tmpfs_dir} is not mounted. Mounting..."
	  mount tmpfs -t tmpfs "${_tmpfs_dir}"

          #if you use debian < 6.x, remove -n
          cp -n ${_database_backup_dir}/murmur.sqlite* ${_tmpfs_dir}/
          
          chown ${_owner}: ${_tmpfs_dir}/murmur.sqlite*
	  echo "Finished :), you can use Mumble now."
      fi
      ;;
  unmount)
      if [ "$(mount | grep ${_tmpfs_dir})" != "" ]; then
	  cp ${_tmpfs_dir}/murmur.sqlite* ${_database_backup_dir}/ 
	  umount "${_tmpfs_dir}"
	  echo "Unmounted."
      else
          echo "${_tmpfs_dir} is not mounted."
      fi
      ;;
  *)
      echo "$0 mount|unmount"
      ;;
esac