[PLUG-JOBS] PLUG-jobs Digest, Vol 97, Issue 4

Shaimon Athimattathil shaimon at gmail.com
Wed Nov 21 21:00:45 UTC 2012


Aaron,
  I saw your e-mail below and wanted to reach out to you. Below is a script
I wrote for a gig I had. This script will keep 7 days of backup on the
local host (note: mysql is not running on default port). In order to move
the files over to the remote server I will write a rsync script and add it
to the cron in addition to this backup cron. I don't consider myself as a
DBA. If you are looking for a seasoned DBA then I'm not a good candidate.
Let me know if you have any interest in seeing my resume.

#! /bin/bash
set -x
umask 077

mkdir -p /data/db/mysql/db/archives

BACKUP_NAME=mysql_db_`date +"%y_%m_%d_%H%M%S"`_backup
TOTAL_BACKUPS=7
DAYFILE=/data/db/mysql/db/archives/dayfile

if [ ! -e  $DAYFILE ]
  then
    echo 1 > $DAYFILE
fi

TIME_ID=`cat $DAYFILE`

BACKUP_HOME=/data/db/mysql/db/archives/${TIME_ID}
mkdir -p ${BACKUP_HOME}

# Archive existing binary logs
cd  /data/db/mysql/db/bin_logs

tar cjf ${BACKUP_HOME}/${BACKUP_NAME}_bin_logs.tbz2 tomato-bin.*

cd ${BACKUP_HOME}


MYSQL_LINK="--socket=/opt/<xx>/stage/db/mysql.sock"



mysqldump --single-transaction --add-drop-database --flush-privileges
--flush-logs --master-data=2 --all-databases $MYSQL_LINK >
${BACKUP_NAME}_full.sql

bzip2 ${BACKUP_NAME}_full.sql

BKUPDIRS=`ls --hide=dayfile -r /data/db/mysql/db/archives/[0-9][0-9]*`
BKUPDIRS=`perl -e '@bkupids = @ARGV; @bkupids = sort {$b <=> $a} @bkupids;
print "@bkupids ";' $BKUPDIRS`

T=0
for x in $BKUPDIRS
 do
   if [ "$x" = "" ]
     then
     continue
   fi
   T=$((T+1))
   if [ $T -gt ${TOTAL_BACKUPS} ]
    then
      echo "/data/db/mysql/db/archives/$x"
       rm -rf "/data/db/mysql/db/archives/$x"
   fi
 done

echo $(($TIME_ID+1)) > $DAYFILE

mysql  $MYSQL_LINK  << endline
reset master;

On Wed, Nov 21, 2012 at 12:00 PM, <plug-jobs-request at lists.pdxlinux.org>wrote:

> aaron at bavariati.org
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.pdxlinux.org/pipermail/plug-jobs/attachments/20121121/dd6ace5f/attachment.html>


More information about the PLUG-jobs mailing list