MySQL Backup Shell Script
#!/bin/bash# A sample mysql backup script# Must be run as the root user# Written by Vivek Gite# Last updated on : 23/Aug/2003# ---------------------------------# MySQL Login InfoMUSER="admin" # MySQL userMHOST="192.168.1.100" # MySQL server ipMPASS="MySQLServerPassword" # MySQL password# format dd-mm-yyyy NOW=$(date +"%d-%m-%Y")# Backupfile pathBPATH=/backup/mysql/$NOW# if backup path does not exists, create it [ ! -d $BPATH ] && mkdir -p $BPATH# get database name listsDBS="$(/usr/bin/mysql -u $MUSER -h $MHOST -p$MPASS -Bse 'show databases')"for db in $DBSdo # Bakcup file name FILE="${BPATH}/${db}.gz" # skip database backup if database name is adserverstats or mint [ "$db" == "adserverstats" ] && continue [ "$db" == "mint" ] && continue # okay lets dump a database backup /usr/bin/mysqldump -u $MUSER -h $MHOST -p$MPASS $db | /bin/gzip -9 > $FILEdone
Start PHP Service in jail
#!/bin/sh# A shell script to start / stop php-cgi process.# Author: Vivek Gite# Last updated on June-23-2007.# ----------------------------------------------fFCGI=/usr/bin/spawn-fcgifIP=127.0.0.1fPORT=9000fUSER=phpjailfGROUP=phpjailfCHILD=10fJAILDIR=/phpjailfPID=/var/run/fcgi.php.pidfPHPCGI=/usr/bin/php-cgi# path to binary files.PKILL=/usr/bin/pkillRM=/bin/rmPGREP=/usr/bin/pgrepGREP=/bin/grepID=/usr/bin/id# Must be run as root else die[ $(${ID} -u) -eq 0 ] || { echo "$0: Only root may run this script."; exit 1; }# Jail user must exits else die${GREP} -q $fUSER /etc/passwd || { echo "$0: User $fUSER not found in /etc/passwd."; exit 2; }# Jail group must exits else die${GREP} -q $fGROUP /etc/passwd || { echo "$0: Group $fGROUP not found in /etc/group."; exit 3; }# Jail directory must exits else die[ ! -d ${fJAILDIR} ] && { echo "$0: php-cgi jail directory \"${fJAILDIR}\" not found."; exit 4; }# Use case to make decision case "$1" in start) # start php-cgi in jail at given IP and server port $fFCGI -a $fIP -p $fPORT -u $fUSER -g $fGROUP -C $fCHILD -c $fJAILDIR -P $fPID -- $fPHPCGI [ $? -eq 0 ] && echo "Starting php-cgi .. [ OK ]" || echo "Starting php-cgi .. [ FAILED ]" ;; stop) # make sure php-cgi is running read line < "$fPID" if [ -d /proc/$line ] then # kill php-cgi owned by user ${PKILL} -KILL -u $fUSER php-cgi [ $? -eq 0 ] && echo "Stopping php-cgi .. [ OK ]" \ || echo "Stopping php-cgi .. [ FAILED ]" ${RM} -f $fPID else echo "$0: php-cgi is not running." fi ;; status) # find out if php-cgi is running or not ${PGREP} -u ${fUSER} php-cgi >/dev/null 2>&1 [ $? -eq 0 ] && echo "$0: php-cgi is running at $fIP:$fPORT" \ || echo "$0: php-cgi is not running at $fIP:$fPORT" ;; *) # display usage echo "Usage: $0 {start|stop|status}"esac
Create a shell script called progressdots.sh
#!/bin/bash# progressdots.sh - Display progress while making backup# Based on idea presnted by nixCraft forum user rockdalinux# Show progress dotsprogress(){ echo -n "$0: Please wait..." while true do echo -n "." sleep 5 done}dobackup(){ # put backup commands here tar -zcvf /dev/st0 /home >/dev/null 2>&1}# Start it in the backgroundprogress &# Save progress() PID# You need to use the PID to kill the functionMYSELF=$!# Start backup# Transfer control to dobackup()dobackup# Kill progresskill $MYSELF >/dev/null 2>&1echo -n "...done."echo