<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Techie Gyaaan &#187; Shell</title>
	<atom:link href="http://techie.gyaaan.com/category/shell/feed/" rel="self" type="application/rss+xml" />
	<link>http://techie.gyaaan.com</link>
	<description>Just another WordPress weblog</description>
	<lastBuildDate>Fri, 15 May 2009 15:19:40 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Shell script to backup MySql database</title>
		<link>http://techie.gyaaan.com/shell-script-to-backup-mysql-database/</link>
		<comments>http://techie.gyaaan.com/shell-script-to-backup-mysql-database/#comments</comments>
		<pubDate>Fri, 15 Feb 2008 10:40:35 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Shell]]></category>
		<category><![CDATA[Backup]]></category>
		<category><![CDATA[Database]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[Shell Script]]></category>

		<guid isPermaLink="false">http://techie.gyaaan.com/?p=34</guid>
		<description><![CDATA[#!/bin/bash # Shell script to backup MySql database # To backup Nysql databases file to /backup dir and later pick up by your # script. You can skip few databases from backup too. # For more info please see (Installation info): # http://www.cyberciti.biz/nixcraft/vivek/blogger/2005/01/mysql-backup-script.html # Last updated: Aug &#8211; 2005 # &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211; # This is a [...]]]></description>
			<content:encoded><![CDATA[<blockquote><p>#!/bin/bash<br />
# Shell script to backup MySql database<br />
# To backup Nysql databases file to /backup dir and later pick up by your<br />
# script. You can skip few databases from backup too.<br />
# For more info please see (Installation info):<br />
# http://www.cyberciti.biz/nixcraft/vivek/blogger/2005/01/mysql-backup-script.html<br />
# Last updated: Aug &#8211; 2005<br />
# &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
# This is a free shell script under GNU GPL version 2.0 or above<br />
# Copyright (C) 2004, 2005 nixCraft project<br />
# Feedback/comment/suggestions : http://cyberciti.biz/fb/<br />
# &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
# This script is part of nixCraft shell script collection (NSSC)<br />
# Visit http://bash.cyberciti.biz/ for more information.<br />
# &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-</p>
<p>MyUSER=&#8221;SET-MYSQL-USER-NAME&#8221;     # USERNAME<br />
MyPASS=&#8221;SET-PASSWORD&#8221;       # PASSWORD<br />
MyHOST=&#8221;localhost&#8221;          # Hostname</p>
<p># Linux bin paths, change this if it can&#8217;t be autodetected via which command<br />
MYSQL=&#8221;$(which mysql)&#8221;<br />
MYSQLDUMP=&#8221;$(which mysqldump)&#8221;<br />
CHOWN=&#8221;$(which chown)&#8221;<br />
CHMOD=&#8221;$(which chmod)&#8221;<br />
GZIP=&#8221;$(which gzip)&#8221;</p>
<p># Backup Dest directory, change this if you have someother location<br />
DEST=&#8221;/backup&#8221;</p>
<p># Main directory where backup will be stored<br />
MBD=&#8221;$DEST/mysql&#8221;</p>
<p># Get hostname<br />
HOST=&#8221;$(hostname)&#8221;</p>
<p># Get data in dd-mm-yyyy format<br />
NOW=&#8221;$(date +&#8221;%d-%m-%Y&#8221;)&#8221;</p>
<p># File to store current backup file<br />
FILE=&#8221;"<br />
# Store list of databases<br />
DBS=&#8221;"</p>
<p># DO NOT BACKUP these databases<br />
IGGY=&#8221;test&#8221;</p>
<p>[ ! -d $MBD ] &#038;&#038; mkdir -p $MBD || :</p>
<p># Only root can access it!<br />
$CHOWN 0.0 -R $DEST<br />
$CHMOD 0600 $DEST</p>
<p># Get all database list first<br />
DBS=&#8221;$($MYSQL -u $MyUSER -h $MyHOST -p$MyPASS -Bse &#8216;show databases&#8217;)&#8221;</p>
<p>for db in $DBS<br />
do<br />
    skipdb=-1<br />
    if [ "$IGGY" != "" ];<br />
    then<br />
	for i in $IGGY<br />
	do<br />
	    [ "$db" == "$i" ] &#038;&#038; skipdb=1 || :<br />
	done<br />
    fi</p>
<p>    if [ "$skipdb" == "-1" ] ; then<br />
	FILE=&#8221;$MBD/$db.$HOST.$NOW.gz&#8221;<br />
	# do all inone job in pipe,<br />
	# connect to mysql using mysqldump for select mysql database<br />
	# and pipe it out to gz file in backup dir <img src='http://techie.gyaaan.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /><br />
        $MYSQLDUMP -u $MyUSER -h $MyHOST -p$MyPASS $db | $GZIP -9 > $FILE<br />
    fi<br />
done</p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://techie.gyaaan.com/shell-script-to-backup-mysql-database/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

