satishgaudo.com

Understanding technology

Archive for October 27th, 2009

shell script to back up database and script folders

#!/bin/bash cd /ct20/uploads/backup/ NOW=$(date +”%m-%d-%Y”) tar -cjf backupsite_$NOW.bz2 /opt/www/ct20 tar -cjf backupcms_$NOW.bz2 /opt/www/cms tar -cjf mysqlbackup_$NOW.bz2 /opt/lib/mysql

27 October 2009 at 12:00 - Comments

shell script to optimize database

DB_LIST=”$(mysql -u root -Bse ’show databases’ | egrep -v ‘information_schema|mysql|test’)” for db in ${DB_LIST[@]} do TABLENAMES=”$(mysql -u root $db -Bse ’show tables’)” echo “Database: “$db for TABLENAME in ${TABLENAMES[@]} do mysql -u root $db -Bse “optimize TABLE $TABLENAME;” echo $TABLENAME” table has been optimized” done echo $db – $TABLENAME “Optimized has been completed” done echo “All Databases have been successfully Optimized”

27 October 2009 at 11:57 - Comments

shell script to Analyze database

DB_LIST=”$(mysql -u root -Bse ’show databases’ | egrep -v ‘information_schema|mysql|test’)” for db in ${DB_LIST[@]} do TABLENAMES=”$(mysql -u root $db -Bse ’show tables’)” echo “Database: “$db for TABLENAME in ${TABLENAMES[@]} do mysql -u root $db -Bse “Analyze TABLE $TABLENAME;” echo $TABLENAME “Analyze has been done” done echo $db – $TABLENAME “Analyzis has been completed” done echo “All Databases have been successfully Optimized”

27 October 2009 at 11:56 - Comments

glob — Find pathnames matching a pattern

$aDir = glob(”/clt20/uploads/videos/*.flv”); The glob() function searches for all the pathnames matching pattern according to the rules used by the libc glob() function, which is similar to the rules used by common shells.

27 October 2009 at 11:54 - Comments

shell script to rotate logs between remote servers

cd /var/log/httpd NOW=$(date +”%m-%d-%Y”) mv mobile-error_log mobile-error_log-$NOW mv mobile-access_log mobile-access_log-$NOW /etc/init.d/httpd graceful sleep 5 tar -cvjf /opt/logbackup/logs-$NOW.bz2 mobile-error_log-$NOW mobile-access_log-$NOW scp mobile-access_log-$NOW domU-12-31-39-07-75-63:/clt20/uploads/mobilelog/ rm -f mobile-error_log-$NOW mobile-access_log-$NOW Remember we have exchanged the authentication key between the two servers.

27 October 2009 at 11:47 - Comments