#!/bin/bash # get real path of softlink get_real_path() { local f="$1" while [ -h "$f" ]; do ls=`ls -ld "$f"` link=`expr "$ls" : '.*-> \(.*\)$'` if expr "$link" : '/.*' > /dev/null; then f="$link" else f=`dirname "$f"`/"$link" fi done eval "$2"="'$f'" } get_real_path "$0" prg_path echo "Script path [$prg_path]" # Service Home pushd $(dirname "$prg_path") > /dev/null SERVICE_HOME=$(dirname $(pwd)) popd > /dev/null # enter service home pushd "$SERVICE_HOME" database=ambition_crm backup_dir="$SERVICE_HOME/backup/$database" restore_file="$backup_dir/${1}.sql.gz" # exit when file not found if [ ! -f "$restore_file" ]; then echo "no restore file [$restore_file] found" exit 1 fi < "$restore_file" gzip -dc | mysql ambition_crm_test # back to previous dir popd > /dev/null