<?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>PlanetMysql.ru - информация о СУБД MySQL &#187; bash</title>
	<atom:link href="http://planetmysql.ru/category/bash/feed/" rel="self" type="application/rss+xml" />
	<link>http://planetmysql.ru</link>
	<description>Блог о самой популярной СУБД MySQL</description>
	<lastBuildDate>Thu, 24 May 2012 14:20:27 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<item>
		<title>Simple and efficient MongoDB Backup using script</title>
		<link>http://feedproxy.google.com/~r/LinuxAdminZone/~3/cBWoPTq6CMo/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=simple-and-efficient-mongodb-backup-using-script</link>
		<comments>http://feedproxy.google.com/~r/LinuxAdminZone/~3/cBWoPTq6CMo/#comments</comments>
		<pubDate>Wed, 09 May 2012 10:17:54 +0000</pubDate>
		<dc:creator>Jagbir Singh</dc:creator>
				<category><![CDATA[bash]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[mongodb]]></category>
		<category><![CDATA[NoSQL]]></category>
		<category><![CDATA[script]]></category>

		<guid isPermaLink="false">http://linuxadminzone.com/?p=511</guid>
		<description><![CDATA[MongoDB Backup types and strategies are neatly explained in its documentation, which you can check here. In case you are not familiar with MongoDB backup types and strategies, please have a look at its documentation.
What I am describing here is a simple script which we are using since months to take MongoDB backup and transfer it over to our Backup server. Here are few things its doing:

As we have multiple MongoDB Replica Sets, the script identify current replica set and check whether current server is Master or Slave, exit if its Master. We take backup only from Slave host.
Take Backup using mongodump command.
Upon successful completion of dump, transfer that to our Backup server. Ensure that ssh key based authentication is setup between both servers to implement seamless and secure transfer. It creates new directory based on current timestamp under replicaset directory in specified path at Backup server and transfer dump there.
Log each steps described above, send alert mail if any step fail with description or send confirmation mail upon successful execution with essential details.
Sample confirmation mail is below:


Subject: Backup for  done on  at 09/May/12 08:00:01 AM
Body: Mongo Backup Status for  on 09/May/12 08:00:01 AM. 
&#160;
08:00:01 AM:  is slave and looks OK.
08:00:01 AM: Starting Dump, executing /usr/local/mongodb/mongo/bin/mongodump --out /databases/dump --host ...
08:34:06 AM: Mongodump command completed. Backup size is 25G. 
08:34:10 AM: Directory created on backup server, copying data using scp...
08:57:00 AM: Copied dump to backup server in directory /home/backup/Mongodump/replicaset/datestamp/.
08:57:00 AM: Mongo Backup process completed successfully.

Here is the full bash script, please note that you need to update variables properly and have to check and update it to run in your environment which can be entirely different from mine. Its just an idea to automate MongoDB backup:

##
# Script to take mongo backup using mongodump and store it in Backup Server
##
&#160;
#!/bin/bash
&#160;
## Set variables
TodayDate=`date +&#34;%d/%b/%g %r&#34;`
DateStamp=`date +%d%m%y%H%M%S`
CurrentTime=`date +&#34;%r&#34;`
&#160;
MongoBinPath=&#34;/usr/local/mongodb/mongo/bin&#34;
ReplicaSet=`echo 'rs.status()' &#124; $MongoBinPath/mongo &#124; egrep &#34;set&#34; &#124; awk -F \&#34; '{print $4}'`
MongoHost=`hostname`
LocalBackupPath=&#34;/databases/dump&#34;
&#160;
LogFile=&#34;/var/log/mongo-backup.log&#34;
IsOK=0
CmdStatus=&#34;&#34;
&#160;
BackupHost=xx.xx.xx.xx
BackupHostPath=&#34;/home/backup/mongobackup&#34;
BackupHostPort=22
&#160;
MailNotification=&#34;admin@domain.com anotheradmin@domain.com&#34;
&#160;
echo -e &#34;Mongo Backup Status for $ReplicaSet on $TodayDate. \n&#34; &#38;gt; $LogFile
&#160;
## Check whether host is slave and in good state for backup
for i in `echo &#34;rs.status()&#34; &#124; $MongoBinPath/mongo &#124; egrep &#34;name&#34; &#124; awk -F \&#34; '{print $4}'&#124; cut -f 1 -d :`; do
 IsMaster=`echo &#34;db.isMaster()&#34;&#124; $MongoBinPath/mongo --host $i &#124; grep ismaster&#124;awk -F &#34;:&#34; '{print $2}' &#124; cut -f 1 -d ,`;
 TheState=`echo &#34;rs.status()&#34;&#124; $MongoBinPath/mongo --host $i &#124; grep -i mystate &#124; awk -F &#34;:&#34; '{print $2}' &#124; cut -f 1 -d ,`;
 if &#091; $IsMaster == &#34;false&#34; -a $TheState -eq 2  &#093;; then
  MongoHost=$i
  IsOK=1
  echo &#34;$CurrentTime: $MongoHost is slave and looks OK.&#34; &#38;gt;&#38;gt; $LogFile
  break
 fi
done
&#160;
CurrentTime=`date +&#34;%r&#34;`
&#160;
## Exit if not good
if &#091; $IsOK -eq 0 &#093;; then
   echo &#34;$CurrentTime: Error: Either $MongoHost is not slave or not in good state. Aborting Backup, Please check!&#34; &#38;gt;&#38;gt; $LogFile
   mail -s &#34;Backup error for $ReplicaSet from $MongoHost on $TodayDate&#34; $MailNotification &#38;lt; $LogFile    exit 1; fi ## Remove earlier backup CmdStatus=$(rm -rf $LocalBackupPath/*) ## Start backup process echo &#34;$CurrentTime: Starting Dump, executing $MongoBinPath/mongodump --out $LocalBackupPath --host $MongoHost...&#34; &#38;gt;&#38;gt; $LogFile
&#160;
CmdStatus=`$MongoBinPath/mongodump --out $LocalBackupPath --host $MongoHost`
if &#091; $? -ne 0 &#093;; then
  echo &#34;$CurrentTime: There is an issue while trying to take dump in $MongoHost. Aborting dump process, please check! &#34; &#38;gt;&#38;gt; $LogFile
  cat $CmdStatus &#38;gt;&#38;gt; $LogFile
  mail -s &#34;Backup error for $ReplicaSet from $MongoHost on $TodayDate&#34; $MailNotification &#38;lt; $LogFile   exit fi CurrentTime=`date +&#34;%r&#34;` BackupSize=$&#040;du -sh $LocalBackupPath/. &#124; awk '{ print $1 }'&#041; echo &#34;$CurrentTime: Mongodump command completed. Backup size is $BackupSize. &#34; &#38;gt;&#38;gt; $LogFile
&#160;
## dump is fine then scp it to backup server
## create directory first
CmdStatus=$&#040;ssh -p $BackupHostPort $BackupHost &#34;mkdir -p  $BackupHostPath/$ReplicaSet/$DateStamp&#34;&#041;
&#160;
if &#091; $? -ne 0 &#093;; then
  echo &#34;$CurrentTime: Either failing to connect Backup server using ssh or destination directory already exist!&#34; &#38;gt;&#38;gt; $LogFile
  cat $CmdStatus &#38;gt;&#38;gt; $LogFile
  mail -s &#34;Backup error for $ReplicaSet from $MongoHost on $TodayDate&#34; $MailNotification &#38;lt; $LogFile   exit fi CurrentTime=`date +&#34;%r&#34;` echo &#34;$CurrentTime: Directory created on backup server, copying data using scp...&#34; &#38;gt;&#38;gt; $LogFile
&#160;
CmdStatus=`scp -P $BackupHostPort -r $LocalBackupPath/* $BackupHost:/$BackupHostPath/$ReplicaSet/$DateStamp/`
if &#091; $? -ne 0 &#093;; then
  echo &#34;$CurrentTime: Unable to scp dump to $BackupHost:/$BackupHostPath/$ReplicaSet/$DateStamp using port $BackupHostPort. &#34; &#38;gt;&#38;gt; $LogFile
  cat $CmdStatus &#38;gt;&#38;gt; $LogFile
  mail -s &#34;Backup error for $ReplicaSet from $MongoHost on $TodayDate&#34; $MailNotification &#38;lt; $LogFile   exit fi CurrentTime=`date +&#34;%r&#34;` echo &#34;$CurrentTime: Copied dump to backup server in directory $BackupHost$BackupHostPath/$ReplicaSet/$DateStamp/.&#34; &#38;gt;&#38;gt; $LogFile
echo &#34;$CurrentTime: Mongo Backup process completed successfully.&#34; &#38;gt;&#38;gt; $LogFile
mail -s &#34;Backup for $ReplicaSet done on $MongoHost at $TodayDate&#34; $MailRecipients $MailNotification &#38;lt; $LogFile

Its just a basic script and may needs further enhancements. In case you have suggestion/queries, please put it below in comments.
More Related and helpful articles:

 Setup multiple MySQL database servers in a single Linux host
Optimize MySQL on a large Database Server 
Recover or reset root password of MySQL and PostgreSQL Servers 
 Optimize and fix MySQL Server running slow without any load 
 How to find out the clients connecting to your MySQL server 
 Quickly repair huge corrupted or crashed table in MySQL 
 Install and configure PhpMyAdmin to manage multiple MySQL Servers 

&#160;]]></description>
			<content:encoded><![CDATA[<p>MongoDB Backup types and strategies are neatly explained in its documentation, which you can check <a href="http://www.mongodb.org/display/DOCS/Backups" >here</a>. In case you are not familiar with MongoDB backup types and strategies, please have a look at its documentation.</p>
<p>What I am describing here is a simple script which we are using since months to take MongoDB backup and transfer it over to our Backup server. Here are few things its doing:</p>
<ul>
<li>As we have multiple MongoDB Replica Sets, the script identify current replica set and check whether current server is Master or Slave, exit if its Master. We take backup only from Slave host.</li>
<li>Take Backup using mongodump command.</li>
<li>Upon successful completion of dump, transfer that to our Backup server. Ensure that ssh key based authentication is setup between both servers to implement seamless and secure transfer. It creates new directory based on current timestamp under replicaset directory in specified path at Backup server and transfer dump there.</li>
<li>Log each steps described above, send alert mail if any step fail with description or send confirmation mail upon successful execution with essential details.</li>
<li>Sample confirmation mail is below:</li>
</ul>

<div><div><pre>Subject: Backup <span>for</span>  <span>done</span> on  at 09<span>/</span>May<span>/</span><span>12</span> 08:00:01 AM
Body: Mongo Backup Status <span>for</span>  on 09<span>/</span>May<span>/</span><span>12</span> 08:00:01 AM. 
&nbsp;
08:00:01 AM:  is slave and looks OK.
08:00:01 AM: Starting Dump, executing <span>/</span>usr<span>/</span>local<span>/</span>mongodb<span>/</span>mongo<span>/</span>bin<span>/</span>mongodump <span>--out</span> <span>/</span>databases<span>/</span>dump <span>--host</span> ...
08:<span>34</span>:06 AM: Mongodump <span>command</span> completed. Backup <span>size</span> is 25G. 
08:<span>34</span>:<span>10</span> AM: Directory created on backup server, copying data using scp...
08:<span>57</span>:00 AM: Copied dump to backup server <span>in</span> directory <span>/</span>home<span>/</span>backup<span>/</span>Mongodump<span>/</span>replicaset<span>/</span>datestamp<span>/</span>.
08:<span>57</span>:00 AM: Mongo Backup process completed successfully.</pre></div></div>

<p>Here is the full bash script, please note that you need to update variables properly and have to check and update it to run in your environment which can be entirely different from mine. Its just an idea to automate MongoDB backup:</p>

<div><div><pre><span>##</span>
<span># Script to take mongo backup using mongodump and store it in Backup Server</span>
<span>##</span>
&nbsp;
<span>#!/bin/bash</span>
&nbsp;
<span>## Set variables</span>
<span>TodayDate</span>=<span>`</span><span>date</span> +<span>&quot;%d/%b/%g %r&quot;</span><span>`</span>
<span>DateStamp</span>=<span>`</span><span>date</span> +<span>%</span>d<span>%</span>m<span>%</span>y<span>%</span>H<span>%</span>M<span>%</span>S<span>`</span>
<span>CurrentTime</span>=<span>`</span><span>date</span> +<span>&quot;%r&quot;</span><span>`</span>
&nbsp;
<span>MongoBinPath</span>=<span>&quot;/usr/local/mongodb/mongo/bin&quot;</span>
<span>ReplicaSet</span>=<span>`</span><span>echo</span> <span>'rs.status()'</span> <span>|</span> <span>$MongoBinPath</span><span>/</span>mongo <span>|</span> <span>egrep</span> <span>&quot;set&quot;</span> <span>|</span> <span>awk</span> <span>-F</span> <span>\&quot;</span> <span>'{print $4}'</span><span>`</span>
<span>MongoHost</span>=<span>`</span><span>hostname</span><span>`</span>
<span>LocalBackupPath</span>=<span>&quot;/databases/dump&quot;</span>
&nbsp;
<span>LogFile</span>=<span>&quot;/var/log/mongo-backup.log&quot;</span>
<span>IsOK</span>=<span>0</span>
<span>CmdStatus</span>=<span>&quot;&quot;</span>
&nbsp;
<span>BackupHost</span>=xx.xx.xx.xx
<span>BackupHostPath</span>=<span>&quot;/home/backup/mongobackup&quot;</span>
<span>BackupHostPort</span>=<span>22</span>
&nbsp;
<span>MailNotification</span>=<span>&quot;admin@domain.com anotheradmin@domain.com&quot;</span>
&nbsp;
<span>echo</span> <span>-e</span> <span>&quot;Mongo Backup Status for <span>$ReplicaSet</span> on <span>$TodayDate</span>. <span>\n</span>&quot;</span> <span>&amp;</span>gt; <span>$LogFile</span>
&nbsp;
<span>## Check whether host is slave and in good state for backup</span>
<span>for</span> i <span>in</span> <span>`</span><span>echo</span> <span>&quot;rs.status()&quot;</span> <span>|</span> <span>$MongoBinPath</span><span>/</span>mongo <span>|</span> <span>egrep</span> <span>&quot;name&quot;</span> <span>|</span> <span>awk</span> <span>-F</span> <span>\&quot;</span> <span>'{print $4}'</span><span>|</span> <span>cut</span> <span>-f</span> <span>1</span> <span>-d</span> :<span>`</span>; <span>do</span>
 <span>IsMaster</span>=<span>`</span><span>echo</span> <span>&quot;db.isMaster()&quot;</span><span>|</span> <span>$MongoBinPath</span><span>/</span>mongo <span>--host</span> <span>$i</span> <span>|</span> <span>grep</span> ismaster<span>|</span><span>awk</span> <span>-F</span> <span>&quot;:&quot;</span> <span>'{print $2}'</span> <span>|</span> <span>cut</span> <span>-f</span> <span>1</span> <span>-d</span> ,<span>`</span>;
 <span>TheState</span>=<span>`</span><span>echo</span> <span>&quot;rs.status()&quot;</span><span>|</span> <span>$MongoBinPath</span><span>/</span>mongo <span>--host</span> <span>$i</span> <span>|</span> <span>grep</span> <span>-i</span> mystate <span>|</span> <span>awk</span> <span>-F</span> <span>&quot;:&quot;</span> <span>'{print $2}'</span> <span>|</span> <span>cut</span> <span>-f</span> <span>1</span> <span>-d</span> ,<span>`</span>;
 <span>if</span> <span>&#91;</span> <span>$IsMaster</span> == <span>&quot;false&quot;</span> <span>-a</span> <span>$TheState</span> <span>-eq</span> <span>2</span>  <span>&#93;</span>; <span>then</span>
  <span>MongoHost</span>=<span>$i</span>
  <span>IsOK</span>=<span>1</span>
  <span>echo</span> <span>&quot;<span>$CurrentTime</span>: <span>$MongoHost</span> is slave and looks OK.&quot;</span> <span>&amp;</span>gt;<span>&amp;</span>gt; <span>$LogFile</span>
  <span>break</span>
 <span>fi</span>
<span>done</span>
&nbsp;
<span>CurrentTime</span>=<span>`</span><span>date</span> +<span>&quot;%r&quot;</span><span>`</span>
&nbsp;
<span>## Exit if not good</span>
<span>if</span> <span>&#91;</span> <span>$IsOK</span> <span>-eq</span> <span>0</span> <span>&#93;</span>; <span>then</span>
   <span>echo</span> <span>&quot;<span>$CurrentTime</span>: Error: Either <span>$MongoHost</span> is not slave or not in good state. Aborting Backup, Please check!&quot;</span> <span>&amp;</span>gt;<span>&amp;</span>gt; <span>$LogFile</span>
   mail <span>-s</span> <span>&quot;Backup error for <span>$ReplicaSet</span> from <span>$MongoHost</span> on <span>$TodayDate</span>&quot;</span> <span>$MailNotification</span> <span>&amp;</span>lt; <span>$LogFile</span>    <span>exit</span> <span>1</span>; <span>fi</span> <span>## Remove earlier backup CmdStatus=$(rm -rf $LocalBackupPath/*) ## Start backup process echo &quot;$CurrentTime: Starting Dump, executing $MongoBinPath/mongodump --out $LocalBackupPath --host $MongoHost...&quot; &amp;gt;&amp;gt; $LogFile</span>
&nbsp;
<span>CmdStatus</span>=<span>`</span><span>$MongoBinPath</span><span>/</span>mongodump <span>--out</span> <span>$LocalBackupPath</span> <span>--host</span> <span>$MongoHost</span><span>`</span>
<span>if</span> <span>&#91;</span> <span>$?</span> <span>-ne</span> <span>0</span> <span>&#93;</span>; <span>then</span>
  <span>echo</span> <span>&quot;<span>$CurrentTime</span>: There is an issue while trying to take dump in <span>$MongoHost</span>. Aborting dump process, please check! &quot;</span> <span>&amp;</span>gt;<span>&amp;</span>gt; <span>$LogFile</span>
  <span>cat</span> <span>$CmdStatus</span> <span>&amp;</span>gt;<span>&amp;</span>gt; <span>$LogFile</span>
  mail <span>-s</span> <span>&quot;Backup error for <span>$ReplicaSet</span> from <span>$MongoHost</span> on <span>$TodayDate</span>&quot;</span> <span>$MailNotification</span> <span>&amp;</span>lt; <span>$LogFile</span>   <span>exit</span> <span>fi</span> <span>CurrentTime</span>=<span>`</span><span>date</span> +<span>&quot;%r&quot;</span><span>`</span> <span>BackupSize</span>=$<span>&#40;</span><span>du</span> <span>-sh</span> <span>$LocalBackupPath</span><span>/</span>. <span>|</span> <span>awk</span> <span>'{ print $1 }'</span><span>&#41;</span> <span>echo</span> <span>&quot;<span>$CurrentTime</span>: Mongodump command completed. Backup size is <span>$BackupSize</span>. &quot;</span> <span>&amp;</span>gt;<span>&amp;</span>gt; <span>$LogFile</span>
&nbsp;
<span>## dump is fine then scp it to backup server</span>
<span>## create directory first</span>
<span>CmdStatus</span>=$<span>&#40;</span><span>ssh</span> <span>-p</span> <span>$BackupHostPort</span> <span>$BackupHost</span> <span>&quot;mkdir -p  <span>$BackupHostPath</span>/<span>$ReplicaSet</span>/<span>$DateStamp</span>&quot;</span><span>&#41;</span>
&nbsp;
<span>if</span> <span>&#91;</span> <span>$?</span> <span>-ne</span> <span>0</span> <span>&#93;</span>; <span>then</span>
  <span>echo</span> <span>&quot;<span>$CurrentTime</span>: Either failing to connect Backup server using ssh or destination directory already exist!&quot;</span> <span>&amp;</span>gt;<span>&amp;</span>gt; <span>$LogFile</span>
  <span>cat</span> <span>$CmdStatus</span> <span>&amp;</span>gt;<span>&amp;</span>gt; <span>$LogFile</span>
  mail <span>-s</span> <span>&quot;Backup error for <span>$ReplicaSet</span> from <span>$MongoHost</span> on <span>$TodayDate</span>&quot;</span> <span>$MailNotification</span> <span>&amp;</span>lt; <span>$LogFile</span>   <span>exit</span> <span>fi</span> <span>CurrentTime</span>=<span>`</span><span>date</span> +<span>&quot;%r&quot;</span><span>`</span> <span>echo</span> <span>&quot;<span>$CurrentTime</span>: Directory created on backup server, copying data using scp...&quot;</span> <span>&amp;</span>gt;<span>&amp;</span>gt; <span>$LogFile</span>
&nbsp;
<span>CmdStatus</span>=<span>`</span><span>scp</span> <span>-P</span> <span>$BackupHostPort</span> <span>-r</span> <span>$LocalBackupPath</span><span>/*</span> <span>$BackupHost</span>:<span>/</span><span>$BackupHostPath</span><span>/</span><span>$ReplicaSet</span><span>/</span><span>$DateStamp</span><span>/`</span>
<span>if</span> <span>&#91;</span> <span>$?</span> <span>-ne</span> <span>0</span> <span>&#93;</span>; <span>then</span>
  <span>echo</span> <span>&quot;<span>$CurrentTime</span>: Unable to scp dump to <span>$BackupHost</span>:/<span>$BackupHostPath</span>/<span>$ReplicaSet</span>/<span>$DateStamp</span> using port <span>$BackupHostPort</span>. &quot;</span> <span>&amp;</span>gt;<span>&amp;</span>gt; <span>$LogFile</span>
  <span>cat</span> <span>$CmdStatus</span> <span>&amp;</span>gt;<span>&amp;</span>gt; <span>$LogFile</span>
  mail <span>-s</span> <span>&quot;Backup error for <span>$ReplicaSet</span> from <span>$MongoHost</span> on <span>$TodayDate</span>&quot;</span> <span>$MailNotification</span> <span>&amp;</span>lt; <span>$LogFile</span>   <span>exit</span> <span>fi</span> <span>CurrentTime</span>=<span>`</span><span>date</span> +<span>&quot;%r&quot;</span><span>`</span> <span>echo</span> <span>&quot;<span>$CurrentTime</span>: Copied dump to backup server in directory <span>$BackupHost</span><span>$BackupHostPath</span>/<span>$ReplicaSet</span>/<span>$DateStamp</span>/.&quot;</span> <span>&amp;</span>gt;<span>&amp;</span>gt; <span>$LogFile</span>
<span>echo</span> <span>&quot;<span>$CurrentTime</span>: Mongo Backup process completed successfully.&quot;</span> <span>&amp;</span>gt;<span>&amp;</span>gt; <span>$LogFile</span>
mail <span>-s</span> <span>&quot;Backup for <span>$ReplicaSet</span> done on <span>$MongoHost</span> at <span>$TodayDate</span>&quot;</span> <span>$MailRecipients</span> <span>$MailNotification</span> <span>&amp;</span>lt; <span>$LogFile</span></pre></div></div>

<p>Its just a basic script and may needs further enhancements. In case you have suggestion/queries, please put it below in comments.</p>
<p><span>More Related and helpful articles:</span></p>
<ul>
<li><a href="http://linuxadminzone.com/optimize-mysql-on-a-large-database-server/"> Setup multiple MySQL database servers in a single Linux host</a></li>
<li><a href="http://linuxadminzone.com/optimize-mysql-on-a-large-database-server/">Optimize MySQL on a large Database Server </a></li>
<li><a href="http://linuxadminzone.com/recover-or-reset-root-password-of-mysql-and-postgresql-servers/">Recover or reset root password of MySQL and PostgreSQL Servers </a></li>
<li><a href="http://linuxadminzone.com/optimize-and-fix-mysql-server-running-slow-without-any-load/"> Optimize and fix MySQL Server running slow without any load </a></li>
<li><a href="http://linuxadminzone.com/find-out-the-clients-of-your-mysql-server/"> How to find out the clients connecting to your MySQL server </a></li>
<li><a href="http://linuxadminzone.com/quickly-repair-a-huge-corrupted-or-crashed-table-in-mysql/"> Quickly repair huge corrupted or crashed table in MySQL </a></li>
<li><a href="http://linuxadminzone.com/install-and-configure-phpmyadmin-to-manage-multiple-mysql-servers/"> Install and configure PhpMyAdmin to manage multiple MySQL Servers </a></li>
</ul>
<p>&nbsp;</p>
<div>
<a href="http://feeds.feedburner.com/~ff/LinuxAdminZone?a=cBWoPTq6CMo:WCWSrFL6_8A:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/LinuxAdminZone?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/LinuxAdminZone?a=cBWoPTq6CMo:WCWSrFL6_8A:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/LinuxAdminZone?i=cBWoPTq6CMo:WCWSrFL6_8A:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/LinuxAdminZone?a=cBWoPTq6CMo:WCWSrFL6_8A:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/LinuxAdminZone?d=qj6IDK7rITs" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/LinuxAdminZone?a=cBWoPTq6CMo:WCWSrFL6_8A:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/LinuxAdminZone?i=cBWoPTq6CMo:WCWSrFL6_8A:D7DqB2pKExk" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/LinuxAdminZone/~4/cBWoPTq6CMo" height="1" width="1" /><br/>PlanetMySQL Voting:
	 <a href="http://planet.mysql.com/entry/vote/?entry_id=33183&vote=1&apivote=1">Vote UP</a> /
	 <a href="http://planet.mysql.com/entry/vote/?entry_id=33183&vote=-1&apivote=1">Vote DOWN</a>]]></content:encoded>
			<wfw:commentRss>http://planetmysql.ru/2012/05/09/simple-and-efficient-mongodb-backup-using-script/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Simple and efficient MongoDB Backup using script</title>
		<link>http://feedproxy.google.com/~r/LinuxAdminZone/~3/cBWoPTq6CMo/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=simple-and-efficient-mongodb-backup-using-script-2</link>
		<comments>http://feedproxy.google.com/~r/LinuxAdminZone/~3/cBWoPTq6CMo/#comments</comments>
		<pubDate>Wed, 09 May 2012 10:17:54 +0000</pubDate>
		<dc:creator>Jagbir Singh</dc:creator>
				<category><![CDATA[bash]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[mongodb]]></category>
		<category><![CDATA[mongodump]]></category>
		<category><![CDATA[NoSQL]]></category>
		<category><![CDATA[script]]></category>

		<guid isPermaLink="false">http://linuxadminzone.com/?p=511</guid>
		<description><![CDATA[MongoDB Backup types and strategies are neatly explained in its documentation, which you can check here. In case you are not familiar with MongoDB backup types and strategies, please have a look at its documentation.
What I am describing here is a simple script which we are using since months to take MongoDB backup and transfer it over to our Backup server. Here are few things its doing:

As we have multiple MongoDB Replica Sets, the script identify current replica set and check whether current server is Master or Slave, exit if its Master. We take backup only from Slave host.
Take Backup using mongodump command.
Upon successful completion of dump, transfer that to our Backup server. Ensure that ssh key based authentication is setup between both servers to implement seamless and secure transfer. It creates new directory based on current timestamp under replicaset directory in specified path at Backup server and transfer dump there.
Log each steps described above, send alert mail if any step fail with description or send confirmation mail upon successful execution with essential details.
Sample confirmation mail is below:


Subject: Backup for  done on  at 09/May/12 08:00:01 AM
Body: Mongo Backup Status for  on 09/May/12 08:00:01 AM. 
&#160;
08:00:01 AM:  is slave and looks OK.
08:00:01 AM: Starting Dump, executing /usr/local/mongodb/mongo/bin/mongodump --out /databases/dump --host ...
08:34:06 AM: Mongodump command completed. Backup size is 25G. 
08:34:10 AM: Directory created on backup server, copying data using scp...
08:57:00 AM: Copied dump to backup server in directory /home/backup/Mongodump/replicaset/datestamp/.
08:57:00 AM: Mongo Backup process completed successfully.

Here is the full bash script, please note that you need to update variables properly and have to check and update it to run in your environment which can be entirely different from mine. Its just an idea to automate MongoDB backup:

##
# Script to take mongo backup using mongodump and store it in Backup Server
##
&#160;
#!/bin/bash
&#160;
## Set variables
TodayDate=`date +&#34;%d/%b/%g %r&#34;`
DateStamp=`date +%d%m%y%H%M%S`
CurrentTime=`date +&#34;%r&#34;`
&#160;
MongoBinPath=&#34;/usr/local/mongodb/mongo/bin&#34;
ReplicaSet=`echo 'rs.status()' &#124; $MongoBinPath/mongo &#124; egrep &#34;set&#34; &#124; awk -F \&#34; '{print $4}'`
MongoHost=`hostname`
LocalBackupPath=&#34;/databases/dump&#34;
&#160;
LogFile=&#34;/var/log/mongo-backup.log&#34;
IsOK=0
CmdStatus=&#34;&#34;
&#160;
BackupHost=xx.xx.xx.xx
BackupHostPath=&#34;/home/backup/mongobackup&#34;
BackupHostPort=22
&#160;
MailNotification=&#34;admin@domain.com anotheradmin@domain.com&#34;
&#160;
echo -e &#34;Mongo Backup Status for $ReplicaSet on $TodayDate. \n&#34; &#38;gt; $LogFile
&#160;
## Check whether host is slave and in good state for backup
for i in `echo &#34;rs.status()&#34; &#124; $MongoBinPath/mongo &#124; egrep &#34;name&#34; &#124; awk -F \&#34; '{print $4}'&#124; cut -f 1 -d :`; do
 IsMaster=`echo &#34;db.isMaster()&#34;&#124; $MongoBinPath/mongo --host $i &#124; grep ismaster&#124;awk -F &#34;:&#34; '{print $2}' &#124; cut -f 1 -d ,`;
 TheState=`echo &#34;rs.status()&#34;&#124; $MongoBinPath/mongo --host $i &#124; grep -i mystate &#124; awk -F &#34;:&#34; '{print $2}' &#124; cut -f 1 -d ,`;
 if &#091; $IsMaster == &#34;false&#34; -a $TheState -eq 2  &#093;; then
  MongoHost=$i
  IsOK=1
  echo &#34;$CurrentTime: $MongoHost is slave and looks OK.&#34; &#38;gt;&#38;gt; $LogFile
  break
 fi
done
&#160;
CurrentTime=`date +&#34;%r&#34;`
&#160;
## Exit if not good
if &#091; $IsOK -eq 0 &#093;; then
   echo &#34;$CurrentTime: Error: Either $MongoHost is not slave or not in good state. Aborting Backup, Please check!&#34; &#38;gt;&#38;gt; $LogFile
   mail -s &#34;Backup error for $ReplicaSet from $MongoHost on $TodayDate&#34; $MailNotification &#38;lt; $LogFile    exit 1; fi ## Remove earlier backup CmdStatus=$(rm -rf $LocalBackupPath/*) ## Start backup process echo &#34;$CurrentTime: Starting Dump, executing $MongoBinPath/mongodump --out $LocalBackupPath --host $MongoHost...&#34; &#38;gt;&#38;gt; $LogFile
&#160;
CmdStatus=`$MongoBinPath/mongodump --out $LocalBackupPath --host $MongoHost`
if &#091; $? -ne 0 &#093;; then
  echo &#34;$CurrentTime: There is an issue while trying to take dump in $MongoHost. Aborting dump process, please check! &#34; &#38;gt;&#38;gt; $LogFile
  cat $CmdStatus &#38;gt;&#38;gt; $LogFile
  mail -s &#34;Backup error for $ReplicaSet from $MongoHost on $TodayDate&#34; $MailNotification &#38;lt; $LogFile   exit fi CurrentTime=`date +&#34;%r&#34;` BackupSize=$&#040;du -sh $LocalBackupPath/. &#124; awk '{ print $1 }'&#041; echo &#34;$CurrentTime: Mongodump command completed. Backup size is $BackupSize. &#34; &#38;gt;&#38;gt; $LogFile
&#160;
## dump is fine then scp it to backup server
## create directory first
CmdStatus=$&#040;ssh -p $BackupHostPort $BackupHost &#34;mkdir -p  $BackupHostPath/$ReplicaSet/$DateStamp&#34;&#041;
&#160;
if &#091; $? -ne 0 &#093;; then
  echo &#34;$CurrentTime: Either failing to connect Backup server using ssh or destination directory already exist!&#34; &#38;gt;&#38;gt; $LogFile
  cat $CmdStatus &#38;gt;&#38;gt; $LogFile
  mail -s &#34;Backup error for $ReplicaSet from $MongoHost on $TodayDate&#34; $MailNotification &#38;lt; $LogFile   exit fi CurrentTime=`date +&#34;%r&#34;` echo &#34;$CurrentTime: Directory created on backup server, copying data using scp...&#34; &#38;gt;&#38;gt; $LogFile
&#160;
CmdStatus=`scp -P $BackupHostPort -r $LocalBackupPath/* $BackupHost:/$BackupHostPath/$ReplicaSet/$DateStamp/`
if &#091; $? -ne 0 &#093;; then
  echo &#34;$CurrentTime: Unable to scp dump to $BackupHost:/$BackupHostPath/$ReplicaSet/$DateStamp using port $BackupHostPort. &#34; &#38;gt;&#38;gt; $LogFile
  cat $CmdStatus &#38;gt;&#38;gt; $LogFile
  mail -s &#34;Backup error for $ReplicaSet from $MongoHost on $TodayDate&#34; $MailNotification &#38;lt; $LogFile   exit fi CurrentTime=`date +&#34;%r&#34;` echo &#34;$CurrentTime: Copied dump to backup server in directory $BackupHost$BackupHostPath/$ReplicaSet/$DateStamp/.&#34; &#38;gt;&#38;gt; $LogFile
echo &#34;$CurrentTime: Mongo Backup process completed successfully.&#34; &#38;gt;&#38;gt; $LogFile
mail -s &#34;Backup for $ReplicaSet done on $MongoHost at $TodayDate&#34; $MailRecipients $MailNotification &#38;lt; $LogFile

Its just a basic script and may needs further enhancements. In case you have suggestion/queries, please put it below in comments.
More Related and helpful articles:

 Setup multiple MySQL database servers in a single Linux host
Optimize MySQL on a large Database Server 
Recover or reset root password of MySQL and PostgreSQL Servers 
 Optimize and fix MySQL Server running slow without any load 
 How to find out the clients connecting to your MySQL server 
 Quickly repair huge corrupted or crashed table in MySQL 
 Install and configure PhpMyAdmin to manage multiple MySQL Servers 

&#160;]]></description>
			<content:encoded><![CDATA[<p>MongoDB Backup types and strategies are neatly explained in its documentation, which you can check <a href="http://www.mongodb.org/display/DOCS/Backups" >here</a>. In case you are not familiar with MongoDB backup types and strategies, please have a look at its documentation.</p>
<p>What I am describing here is a simple script which we are using since months to take MongoDB backup and transfer it over to our Backup server. Here are few things its doing:</p>
<ul>
<li>As we have multiple MongoDB Replica Sets, the script identify current replica set and check whether current server is Master or Slave, exit if its Master. We take backup only from Slave host.</li>
<li>Take Backup using mongodump command.</li>
<li>Upon successful completion of dump, transfer that to our Backup server. Ensure that ssh key based authentication is setup between both servers to implement seamless and secure transfer. It creates new directory based on current timestamp under replicaset directory in specified path at Backup server and transfer dump there.</li>
<li>Log each steps described above, send alert mail if any step fail with description or send confirmation mail upon successful execution with essential details.</li>
<li>Sample confirmation mail is below:</li>
</ul>

<div><div><pre>Subject: Backup <span>for</span>  <span>done</span> on  at 09<span>/</span>May<span>/</span><span>12</span> 08:00:01 AM
Body: Mongo Backup Status <span>for</span>  on 09<span>/</span>May<span>/</span><span>12</span> 08:00:01 AM. 
&nbsp;
08:00:01 AM:  is slave and looks OK.
08:00:01 AM: Starting Dump, executing <span>/</span>usr<span>/</span>local<span>/</span>mongodb<span>/</span>mongo<span>/</span>bin<span>/</span>mongodump <span>--out</span> <span>/</span>databases<span>/</span>dump <span>--host</span> ...
08:<span>34</span>:06 AM: Mongodump <span>command</span> completed. Backup <span>size</span> is 25G. 
08:<span>34</span>:<span>10</span> AM: Directory created on backup server, copying data using scp...
08:<span>57</span>:00 AM: Copied dump to backup server <span>in</span> directory <span>/</span>home<span>/</span>backup<span>/</span>Mongodump<span>/</span>replicaset<span>/</span>datestamp<span>/</span>.
08:<span>57</span>:00 AM: Mongo Backup process completed successfully.</pre></div></div>

<p>Here is the full bash script, please note that you need to update variables properly and have to check and update it to run in your environment which can be entirely different from mine. Its just an idea to automate MongoDB backup:</p>

<div><div><pre><span>##</span>
<span># Script to take mongo backup using mongodump and store it in Backup Server</span>
<span>##</span>
&nbsp;
<span>#!/bin/bash</span>
&nbsp;
<span>## Set variables</span>
<span>TodayDate</span>=<span>`</span><span>date</span> +<span>&quot;%d/%b/%g %r&quot;</span><span>`</span>
<span>DateStamp</span>=<span>`</span><span>date</span> +<span>%</span>d<span>%</span>m<span>%</span>y<span>%</span>H<span>%</span>M<span>%</span>S<span>`</span>
<span>CurrentTime</span>=<span>`</span><span>date</span> +<span>&quot;%r&quot;</span><span>`</span>
&nbsp;
<span>MongoBinPath</span>=<span>&quot;/usr/local/mongodb/mongo/bin&quot;</span>
<span>ReplicaSet</span>=<span>`</span><span>echo</span> <span>'rs.status()'</span> <span>|</span> <span>$MongoBinPath</span><span>/</span>mongo <span>|</span> <span>egrep</span> <span>&quot;set&quot;</span> <span>|</span> <span>awk</span> <span>-F</span> <span>\&quot;</span> <span>'{print $4}'</span><span>`</span>
<span>MongoHost</span>=<span>`</span><span>hostname</span><span>`</span>
<span>LocalBackupPath</span>=<span>&quot;/databases/dump&quot;</span>
&nbsp;
<span>LogFile</span>=<span>&quot;/var/log/mongo-backup.log&quot;</span>
<span>IsOK</span>=<span>0</span>
<span>CmdStatus</span>=<span>&quot;&quot;</span>
&nbsp;
<span>BackupHost</span>=xx.xx.xx.xx
<span>BackupHostPath</span>=<span>&quot;/home/backup/mongobackup&quot;</span>
<span>BackupHostPort</span>=<span>22</span>
&nbsp;
<span>MailNotification</span>=<span>&quot;admin@domain.com anotheradmin@domain.com&quot;</span>
&nbsp;
<span>echo</span> <span>-e</span> <span>&quot;Mongo Backup Status for <span>$ReplicaSet</span> on <span>$TodayDate</span>. <span>\n</span>&quot;</span> <span>&amp;</span>gt; <span>$LogFile</span>
&nbsp;
<span>## Check whether host is slave and in good state for backup</span>
<span>for</span> i <span>in</span> <span>`</span><span>echo</span> <span>&quot;rs.status()&quot;</span> <span>|</span> <span>$MongoBinPath</span><span>/</span>mongo <span>|</span> <span>egrep</span> <span>&quot;name&quot;</span> <span>|</span> <span>awk</span> <span>-F</span> <span>\&quot;</span> <span>'{print $4}'</span><span>|</span> <span>cut</span> <span>-f</span> <span>1</span> <span>-d</span> :<span>`</span>; <span>do</span>
 <span>IsMaster</span>=<span>`</span><span>echo</span> <span>&quot;db.isMaster()&quot;</span><span>|</span> <span>$MongoBinPath</span><span>/</span>mongo <span>--host</span> <span>$i</span> <span>|</span> <span>grep</span> ismaster<span>|</span><span>awk</span> <span>-F</span> <span>&quot;:&quot;</span> <span>'{print $2}'</span> <span>|</span> <span>cut</span> <span>-f</span> <span>1</span> <span>-d</span> ,<span>`</span>;
 <span>TheState</span>=<span>`</span><span>echo</span> <span>&quot;rs.status()&quot;</span><span>|</span> <span>$MongoBinPath</span><span>/</span>mongo <span>--host</span> <span>$i</span> <span>|</span> <span>grep</span> <span>-i</span> mystate <span>|</span> <span>awk</span> <span>-F</span> <span>&quot;:&quot;</span> <span>'{print $2}'</span> <span>|</span> <span>cut</span> <span>-f</span> <span>1</span> <span>-d</span> ,<span>`</span>;
 <span>if</span> <span>&#91;</span> <span>$IsMaster</span> == <span>&quot;false&quot;</span> <span>-a</span> <span>$TheState</span> <span>-eq</span> <span>2</span>  <span>&#93;</span>; <span>then</span>
  <span>MongoHost</span>=<span>$i</span>
  <span>IsOK</span>=<span>1</span>
  <span>echo</span> <span>&quot;<span>$CurrentTime</span>: <span>$MongoHost</span> is slave and looks OK.&quot;</span> <span>&amp;</span>gt;<span>&amp;</span>gt; <span>$LogFile</span>
  <span>break</span>
 <span>fi</span>
<span>done</span>
&nbsp;
<span>CurrentTime</span>=<span>`</span><span>date</span> +<span>&quot;%r&quot;</span><span>`</span>
&nbsp;
<span>## Exit if not good</span>
<span>if</span> <span>&#91;</span> <span>$IsOK</span> <span>-eq</span> <span>0</span> <span>&#93;</span>; <span>then</span>
   <span>echo</span> <span>&quot;<span>$CurrentTime</span>: Error: Either <span>$MongoHost</span> is not slave or not in good state. Aborting Backup, Please check!&quot;</span> <span>&amp;</span>gt;<span>&amp;</span>gt; <span>$LogFile</span>
   mail <span>-s</span> <span>&quot;Backup error for <span>$ReplicaSet</span> from <span>$MongoHost</span> on <span>$TodayDate</span>&quot;</span> <span>$MailNotification</span> <span>&amp;</span>lt; <span>$LogFile</span>    <span>exit</span> <span>1</span>; <span>fi</span> <span>## Remove earlier backup CmdStatus=$(rm -rf $LocalBackupPath/*) ## Start backup process echo &quot;$CurrentTime: Starting Dump, executing $MongoBinPath/mongodump --out $LocalBackupPath --host $MongoHost...&quot; &amp;gt;&amp;gt; $LogFile</span>
&nbsp;
<span>CmdStatus</span>=<span>`</span><span>$MongoBinPath</span><span>/</span>mongodump <span>--out</span> <span>$LocalBackupPath</span> <span>--host</span> <span>$MongoHost</span><span>`</span>
<span>if</span> <span>&#91;</span> <span>$?</span> <span>-ne</span> <span>0</span> <span>&#93;</span>; <span>then</span>
  <span>echo</span> <span>&quot;<span>$CurrentTime</span>: There is an issue while trying to take dump in <span>$MongoHost</span>. Aborting dump process, please check! &quot;</span> <span>&amp;</span>gt;<span>&amp;</span>gt; <span>$LogFile</span>
  <span>cat</span> <span>$CmdStatus</span> <span>&amp;</span>gt;<span>&amp;</span>gt; <span>$LogFile</span>
  mail <span>-s</span> <span>&quot;Backup error for <span>$ReplicaSet</span> from <span>$MongoHost</span> on <span>$TodayDate</span>&quot;</span> <span>$MailNotification</span> <span>&amp;</span>lt; <span>$LogFile</span>   <span>exit</span> <span>fi</span> <span>CurrentTime</span>=<span>`</span><span>date</span> +<span>&quot;%r&quot;</span><span>`</span> <span>BackupSize</span>=$<span>&#40;</span><span>du</span> <span>-sh</span> <span>$LocalBackupPath</span><span>/</span>. <span>|</span> <span>awk</span> <span>'{ print $1 }'</span><span>&#41;</span> <span>echo</span> <span>&quot;<span>$CurrentTime</span>: Mongodump command completed. Backup size is <span>$BackupSize</span>. &quot;</span> <span>&amp;</span>gt;<span>&amp;</span>gt; <span>$LogFile</span>
&nbsp;
<span>## dump is fine then scp it to backup server</span>
<span>## create directory first</span>
<span>CmdStatus</span>=$<span>&#40;</span><span>ssh</span> <span>-p</span> <span>$BackupHostPort</span> <span>$BackupHost</span> <span>&quot;mkdir -p  <span>$BackupHostPath</span>/<span>$ReplicaSet</span>/<span>$DateStamp</span>&quot;</span><span>&#41;</span>
&nbsp;
<span>if</span> <span>&#91;</span> <span>$?</span> <span>-ne</span> <span>0</span> <span>&#93;</span>; <span>then</span>
  <span>echo</span> <span>&quot;<span>$CurrentTime</span>: Either failing to connect Backup server using ssh or destination directory already exist!&quot;</span> <span>&amp;</span>gt;<span>&amp;</span>gt; <span>$LogFile</span>
  <span>cat</span> <span>$CmdStatus</span> <span>&amp;</span>gt;<span>&amp;</span>gt; <span>$LogFile</span>
  mail <span>-s</span> <span>&quot;Backup error for <span>$ReplicaSet</span> from <span>$MongoHost</span> on <span>$TodayDate</span>&quot;</span> <span>$MailNotification</span> <span>&amp;</span>lt; <span>$LogFile</span>   <span>exit</span> <span>fi</span> <span>CurrentTime</span>=<span>`</span><span>date</span> +<span>&quot;%r&quot;</span><span>`</span> <span>echo</span> <span>&quot;<span>$CurrentTime</span>: Directory created on backup server, copying data using scp...&quot;</span> <span>&amp;</span>gt;<span>&amp;</span>gt; <span>$LogFile</span>
&nbsp;
<span>CmdStatus</span>=<span>`</span><span>scp</span> <span>-P</span> <span>$BackupHostPort</span> <span>-r</span> <span>$LocalBackupPath</span><span>/*</span> <span>$BackupHost</span>:<span>/</span><span>$BackupHostPath</span><span>/</span><span>$ReplicaSet</span><span>/</span><span>$DateStamp</span><span>/`</span>
<span>if</span> <span>&#91;</span> <span>$?</span> <span>-ne</span> <span>0</span> <span>&#93;</span>; <span>then</span>
  <span>echo</span> <span>&quot;<span>$CurrentTime</span>: Unable to scp dump to <span>$BackupHost</span>:/<span>$BackupHostPath</span>/<span>$ReplicaSet</span>/<span>$DateStamp</span> using port <span>$BackupHostPort</span>. &quot;</span> <span>&amp;</span>gt;<span>&amp;</span>gt; <span>$LogFile</span>
  <span>cat</span> <span>$CmdStatus</span> <span>&amp;</span>gt;<span>&amp;</span>gt; <span>$LogFile</span>
  mail <span>-s</span> <span>&quot;Backup error for <span>$ReplicaSet</span> from <span>$MongoHost</span> on <span>$TodayDate</span>&quot;</span> <span>$MailNotification</span> <span>&amp;</span>lt; <span>$LogFile</span>   <span>exit</span> <span>fi</span> <span>CurrentTime</span>=<span>`</span><span>date</span> +<span>&quot;%r&quot;</span><span>`</span> <span>echo</span> <span>&quot;<span>$CurrentTime</span>: Copied dump to backup server in directory <span>$BackupHost</span><span>$BackupHostPath</span>/<span>$ReplicaSet</span>/<span>$DateStamp</span>/.&quot;</span> <span>&amp;</span>gt;<span>&amp;</span>gt; <span>$LogFile</span>
<span>echo</span> <span>&quot;<span>$CurrentTime</span>: Mongo Backup process completed successfully.&quot;</span> <span>&amp;</span>gt;<span>&amp;</span>gt; <span>$LogFile</span>
mail <span>-s</span> <span>&quot;Backup for <span>$ReplicaSet</span> done on <span>$MongoHost</span> at <span>$TodayDate</span>&quot;</span> <span>$MailRecipients</span> <span>$MailNotification</span> <span>&amp;</span>lt; <span>$LogFile</span></pre></div></div>

<p>Its just a basic script and may needs further enhancements. In case you have suggestion/queries, please put it below in comments.</p>
<p><span>More Related and helpful articles:</span></p>
<ul>
<li><a href="http://linuxadminzone.com/optimize-mysql-on-a-large-database-server/"> Setup multiple MySQL database servers in a single Linux host</a></li>
<li><a href="http://linuxadminzone.com/optimize-mysql-on-a-large-database-server/">Optimize MySQL on a large Database Server </a></li>
<li><a href="http://linuxadminzone.com/recover-or-reset-root-password-of-mysql-and-postgresql-servers/">Recover or reset root password of MySQL and PostgreSQL Servers </a></li>
<li><a href="http://linuxadminzone.com/optimize-and-fix-mysql-server-running-slow-without-any-load/"> Optimize and fix MySQL Server running slow without any load </a></li>
<li><a href="http://linuxadminzone.com/find-out-the-clients-of-your-mysql-server/"> How to find out the clients connecting to your MySQL server </a></li>
<li><a href="http://linuxadminzone.com/quickly-repair-a-huge-corrupted-or-crashed-table-in-mysql/"> Quickly repair huge corrupted or crashed table in MySQL </a></li>
<li><a href="http://linuxadminzone.com/install-and-configure-phpmyadmin-to-manage-multiple-mysql-servers/"> Install and configure PhpMyAdmin to manage multiple MySQL Servers </a></li>
</ul>
<p>&nbsp;</p>
<div>
<a href="http://feeds.feedburner.com/~ff/LinuxAdminZone?a=cBWoPTq6CMo:WCWSrFL6_8A:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/LinuxAdminZone?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/LinuxAdminZone?a=cBWoPTq6CMo:WCWSrFL6_8A:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/LinuxAdminZone?i=cBWoPTq6CMo:WCWSrFL6_8A:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/LinuxAdminZone?a=cBWoPTq6CMo:WCWSrFL6_8A:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/LinuxAdminZone?d=qj6IDK7rITs" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/LinuxAdminZone?a=cBWoPTq6CMo:WCWSrFL6_8A:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/LinuxAdminZone?i=cBWoPTq6CMo:WCWSrFL6_8A:D7DqB2pKExk" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/LinuxAdminZone/~4/cBWoPTq6CMo" height="1" width="1" /><br/>PlanetMySQL Voting:
	 <a href="http://planet.mysql.com/entry/vote/?entry_id=33183&vote=1&apivote=1">Vote UP</a> /
	 <a href="http://planet.mysql.com/entry/vote/?entry_id=33183&vote=-1&apivote=1">Vote DOWN</a>]]></content:encoded>
			<wfw:commentRss>http://planetmysql.ru/2012/05/09/simple-and-efficient-mongodb-backup-using-script-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Fun with Bash :: one liners</title>
		<link>http://feedproxy.google.com/~r/Themattreid/~3/8Fc5AGPo8T4/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=fun-with-bash-one-liners</link>
		<comments>http://feedproxy.google.com/~r/Themattreid/~3/8Fc5AGPo8T4/#comments</comments>
		<pubDate>Tue, 10 Apr 2012 18:13:30 +0000</pubDate>
		<dc:creator>Matt Reid</dc:creator>
				<category><![CDATA[bash]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[scripts]]></category>
		<category><![CDATA[shell commands]]></category>

		<guid isPermaLink="false">http://themattreid.com/wordpress/?p=509</guid>
		<description><![CDATA[Here are some quick and easy bash commands to solve every day problems I run into. Comment and leave some of your own if you like. I might update this post with new ones over time. These are just some common ones. 

Iterate through directory listing and remove the file extension from each file
ls -1 &#124; while read each; do new=`echo $each &#124;sed 's/\(.*\)\..*/\1/'` &#38;&#38; echo $new &#38;&#38; mv "$each" "$new"; done

Output relevant process info, and nothing else
ps axo "user,pid,ppid,%cpu,%mem,tty,stime,state,command"&#124; grep -v "grep" &#124; grep $your-string-here

Setup a SOCKS5 proxy on localhost port 5050, to tunnel all traffic through a destination server
ssh -N -D 5050 username@destination_server'

Setup a SOCKS5 proxy via a remote TOR connection, using local port 5050 and remote TOR port 9050
ssh -L 5050:127.0.0.1:9050 username@destination_server'

Display text or code file contents to screen but don't display any # comment lines
sed -e '/^#/d' $1 &#60; $file_name_here

Same as above but replacing # lines with blank lines
sed -e &#039;/^#/g&#039; $1  /dev/null]]></description>
			<content:encoded><![CDATA[<p>Here are some quick and easy bash commands to solve every day problems I run into. Comment and leave some of your own if you like. I might update this post with new ones over time. These are just some common ones. </p>
<pre name="code">
Iterate through directory listing and remove the file extension from each file
ls -1 | while read each; do new=`echo $each |sed 's/\(.*\)\..*/\1/'` &amp;&amp; echo $new &amp;&amp; mv "$each" "$new"; done

Output relevant process info, and nothing else
ps axo "user,pid,ppid,%cpu,%mem,tty,stime,state,command"| grep -v "grep" | grep $your-string-here

Setup a SOCKS5 proxy on localhost port 5050, to tunnel all traffic through a destination server
ssh -N -D 5050 username@destination_server'

Setup a SOCKS5 proxy via a remote TOR connection, using local port 5050 and remote TOR port 9050
ssh -L 5050:127.0.0.1:9050 username@destination_server'

Display text or code file contents to screen but don't display any # comment lines
sed -e '/^#/d' $1 < $file_name_here

Same as above but replacing # lines with blank lines
sed -e '/^#/g' $1 < $file_name_here

Find all symlinks in the current directory and subdirs
find ./ -type l -exec ls -l {} \;

Find all executable files in current directory and subdirs
find ./ -type f -perm -o+rx -exec ls -ld '{}' \;

Remove all files matching the input string
echo -n "filename match to remove [rm -i]: " &#038;&#038; read f; find ./ -name ${f} -exec rm -i {} \;

Display largest ten files in current dir and subdirs
du -a ./ | sort -n -r | head -n 10

Display all files in current dir and subdirs in order of filesize
du -a ./ | sort -n -r

Generate a MD5 hash for the input string (not file)
Linux: echo -n "str: " &#038;&#038; read x &#038;&#038; echo -n "$x" | md5sum
OSX: echo -n "str: " &#038;&#038; read x &#038;&#038; echo -n "$x" | md5

Display a summary of all files in current and subdirs
for t in files links directories; do echo `find . -type ${t:0:1} | wc -l` $t; done 2> /dev/null</pre>
<img src="http://feeds.feedburner.com/~r/Themattreid/~4/8Fc5AGPo8T4" height="1" width="1" /><br/>PlanetMySQL Voting:
	 <a href="http://planet.mysql.com/entry/vote/?entry_id=32811&vote=1&apivote=1">Vote UP</a> /
	 <a href="http://planet.mysql.com/entry/vote/?entry_id=32811&vote=-1&apivote=1">Vote DOWN</a>]]></content:encoded>
			<wfw:commentRss>http://planetmysql.ru/2012/04/10/fun-with-bash-one-liners/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Alias shortcuts to MySQL CLI</title>
		<link>http://en.latindevelopers.com/ivancp/2012/alias-shortcuts-to-mysql-cli/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=alias-shortcuts-to-mysql-cli</link>
		<comments>http://en.latindevelopers.com/ivancp/2012/alias-shortcuts-to-mysql-cli/#comments</comments>
		<pubDate>Fri, 02 Mar 2012 04:53:39 +0000</pubDate>
		<dc:creator>Ivan Cachicatari</dc:creator>
				<category><![CDATA[bash]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[mysql-cli]]></category>

		<guid isPermaLink="false">http://en.latindevelopers.com/ivancp/?p=55</guid>
		<description><![CDATA[Do you get write laziness in the command line everything what you need to connect to a MySQL server every time?
It may take less than minute, but sometimes one minute is vital (especially if we&#8217;re near the end of the world):


ivancp@ubuntu$ mysql -u root -p -h mysqlhost database


When we are hurry, these commands often fail several times per minute.
The solution: we can create shortcuts with bash alias commands in file ~/.bashrc :


# File ~ /. Bashrc
&#160;
# Command &#34;my&#34; to connect to a local server
alias my='mysql -u root -p'
&#160;
# Command &#34;my2&#34; to connect to a remote server
alias my2='mysql -u root -h 192.168.1.56 -p'


Next time if you want to access the local server just type the command my [database name] , there only ask for database password. You can use any command aliases, I prefer  &#8220;my&#8221; and &#8220;my2&#8243; they are short and useful.
But if you have several servers comes another problem, how to know in which server I&#8217;m?
Open a mysql-cli can be super fast with alias shortcuts, but all terminals have the same default prompt: mysql&#62;  To avoid disasters (ex. run DROP in wrong place) you can change mysql-cli prompt with option --prompt , then finally our .bashrc look like this:


#improved ~/.bashrc 
&#160;
# Command &#34;my&#34; to connect to a local server
alias my='mysql -u root --password=secret --prompt=&#34;local&#62; &#34;'
&#160;
# Command &#34;my2&#34; to connect to a remote server
alias my2='mysql -u root --password=secret  -h 192.168.1.56 --prompt=&#34;server 1&#62; &#34;'


Note I added --password parameter, it can be dangerous, use it under your own risk.
Enjoy!]]></description>
			<content:encoded><![CDATA[<p>Do you get write laziness in the command line everything what you need to connect to a MySQL server every time?</p>
<p>It may take less than minute, but sometimes one minute is vital (especially if we&#8217;re near the end of the world):</p>


<div><div><div><div><div><div><div><pre><span>ivancp@ubuntu$ </span>mysql <span>-u</span> root <span>-p</span> <span>-h</span> mysqlhost database</pre></div></div></div></div></div></div></div>


<p>When we are hurry, these commands often fail several times per minute.</p>
<p>The solution: we can create shortcuts with bash alias commands in file ~/.bashrc :</p>


<div><div><div><div><div><div><div><pre><span># File ~ /. Bashrc</span>
&nbsp;
<span># Command &quot;my&quot; to connect to a local server</span>
<span>alias</span> <span>my</span>=<span>'mysql -u root -p'</span>
&nbsp;
<span># Command &quot;my2&quot; to connect to a remote server</span>
<span>alias</span> <span>my2</span>=<span>'mysql -u root -h 192.168.1.56 -p'</span></pre></div></div></div></div></div></div></div>


<p>Next time if you want to access the local server just type the command <code>my [database name]</code> , there only ask for database password. You can use any command aliases, I prefer  &#8220;my&#8221; and &#8220;my2&#8243; they are short and useful.</p>
<p>But if you have several servers comes another problem, how to know in which server I&#8217;m?</p>
<p>Open a mysql-cli can be super fast with alias shortcuts, but all terminals have the same default prompt: <code>mysql&gt;</code>  To avoid disasters (ex. run DROP in wrong place) you can change mysql-cli prompt with option <code>--prompt</code> , then finally our .bashrc look like this:</p>


<div><div><div><div><div><div><div><pre><span>#improved ~/.bashrc </span>
&nbsp;
<span># Command &quot;my&quot; to connect to a local server</span>
<span>alias</span> <span>my</span>=<span>'mysql -u root --password=secret --prompt=&quot;local&gt; &quot;'</span>
&nbsp;
<span># Command &quot;my2&quot; to connect to a remote server</span>
<span>alias</span> <span>my2</span>=<span>'mysql -u root --password=secret  -h 192.168.1.56 --prompt=&quot;server 1&gt; &quot;'</span></pre></div></div></div></div></div></div></div>


<p>Note I added <code>--password</code> parameter, it can be dangerous, use it under your own risk.</p>
<p>Enjoy!</p><br/>PlanetMySQL Voting:
	 <a href="http://planet.mysql.com/entry/vote/?entry_id=32203&vote=1&apivote=1">Vote UP</a> /
	 <a href="http://planet.mysql.com/entry/vote/?entry_id=32203&vote=-1&apivote=1">Vote DOWN</a>]]></content:encoded>
			<wfw:commentRss>http://planetmysql.ru/2012/03/02/alias-shortcuts-to-mysql-cli/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Fun with Bash: aliases make your live easier&#8230; share your favorites</title>
		<link>http://feedproxy.google.com/~r/Themattreid/~3/ZGDuXjwThXs/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=fun-with-bash-aliases-make-your-live-easier-share-your-favorites</link>
		<comments>http://feedproxy.google.com/~r/Themattreid/~3/ZGDuXjwThXs/#comments</comments>
		<pubDate>Thu, 10 Feb 2011 04:19:04 +0000</pubDate>
		<dc:creator>Matt Reid</dc:creator>
				<category><![CDATA[bash]]></category>
		<category><![CDATA[bashrc]]></category>
		<category><![CDATA[BSD]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[scripts]]></category>

		<guid isPermaLink="false">http://themattreid.com/wordpress/?p=469</guid>
		<description><![CDATA[I&#8217;ve always been a big fan of having a customized .bashrc file. The one I distribute to all of my servers has aliases for quick commands to save me time on the command line, functions that get work done when aliases are too simplistic, reporting for the server for each cli login, and of course a formatted and colored prompt (for terms that support colors). I also change certain aspects and commands based on the operating system since I&#8217;m not always on a redhat box or linux at all. Here&#8217;s my bashrc file &#8211; maybe you have some fun additions that you&#8217;d like to share. What saves you time on the command line?]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve always been a big fan of having a customized .bashrc file. The one I distribute to all of my servers has aliases for quick commands to save me time on the command line, functions that get work done when aliases are too simplistic, reporting for the server for each cli login, and of course a formatted and colored prompt (for terms that support colors). I also change certain aspects and commands based on the operating system since I&#8217;m not always on a redhat box or linux at all. <a href="http://pastebin.com/sVw8guUE">Here&#8217;s my bashrc file</a> &#8211; maybe you have some fun additions that you&#8217;d like to share. What saves you time on the command line? </p>
<img src="http://feeds.feedburner.com/~r/Themattreid/~4/ZGDuXjwThXs" height="1" width="1" /><br/>PlanetMySQL Voting:
	 <a href="http://planet.mysql.com/entry/vote/?entry_id=27276&vote=1&apivote=1">Vote UP</a> /
	 <a href="http://planet.mysql.com/entry/vote/?entry_id=27276&vote=-1&apivote=1">Vote DOWN</a>]]></content:encoded>
			<wfw:commentRss>http://planetmysql.ru/2011/02/10/fun-with-bash-aliases-make-your-live-easier-share-your-favorites/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>[Bash] Performing array intersection with Bash</title>
		<link>http://crazytoon.com/2010/10/25/bash-performing-array-intersection-with-bash/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=bash-performing-array-intersection-with-bash</link>
		<comments>http://crazytoon.com/2010/10/25/bash-performing-array-intersection-with-bash/#comments</comments>
		<pubDate>Tue, 26 Oct 2010 01:15:51 +0000</pubDate>
		<dc:creator>Sunny Walia</dc:creator>
				<category><![CDATA[bash]]></category>
		<category><![CDATA[CentOS]]></category>
		<category><![CDATA[Linux Apache MySQL PHP]]></category>
		<category><![CDATA[Linux System]]></category>
		<category><![CDATA[Linux Tips]]></category>

		<guid isPermaLink="false">http://crazytoon.com/?p=224</guid>
		<description><![CDATA[I am currently working on a project to deploy new website builds to a
small number of servers.  I needed something simple and reliable that could
be built in a very short period of time.  I decided to whip something up in
bash with the intent of refining it in Python later.
As I began to write this code, I realized that it probably would have been
quicker to do it in Python from the start.  I decided to stick with bash as
somewhat of an academic exercise.  The vast majority of these deployment
scripts were trivial; check the code out of git, create a manifest, package
it up, spew it to the servers, etc, etc.  The problem came during the last
step.  We decided to use a symlink to point to the active build out of a
number of builds that could be available on the server at any given time.
Since all of our servers should be running the exact same version of the
build, it makes sense that I should only allow a user of my deployment
scripts to link a build which exists on all servers.  But how do you
accomplish this in bash?
In most other languages, you have access to numerous array helping
functions that allow you to perform intersects, uniqs, and merges.  My goal
was to do the same thing in bash without forking out to any external
binary.  So how do you ensure that a particular thing exists on N number of
servers?  Here it is:
function in_array() {
 local x
 ENTRY=$1
 shift 1
 ARRAY=( "$@" )
 [ -z "${ARRAY}" ] &#38;&#38; return 1
 [ -z "${ENTRY}" ] &#38;&#38; return 1
 for x in ${ARRAY[@]}; do
   [ "${x}" == "${ENTRY}" ] &#38;&#38; return 0
 done
 return 1
}

MASTER=()
CURRENT=()
FIRST=1
for SERVER in ${SERVERS}; do
 # collect all builds from server and populate CURRENT list
 COMMAND="${LS} -1fd ${WEBROOT}/${SITE}.*"
 BUILDS=`${SSH} ${SSHOPTS} root@${SERVER} "${COMMAND}"`
 for BUILD in ${BUILDS}; do
   CURRENT=( ${CURRENT[@]-} ${BUILD} )
 done

 # if this is our first time around, copy CURRENT to MASTER
 if [ ${FIRST} -eq 1 ]; then
   MASTER=( ${CURRENT[@]} )
   FIRST=0
 fi

 # now we do a compare between MASTER and CURRENT to see what builds
 # are common
 INTERSECT=()
 for ENTRY in ${CURRENT[@]}; do
   in_array "${ENTRY}" "${MASTER[@]}"
   RET=$?
   if [ "${RET}" -eq 0 ]; then
     INTERSECT=( ${INTERSECT[@]-} ${ENTRY} )
   fi
 done
 MASTER=( ${INTERSECT[@]} )

 # clear the CURRENT array
 CURRENT=()
done
Let me take a moment to explain the code above:

 In order to check for array intersection, you need an in_array()
function

The first argument as the &#8220;needle&#8221; and the second is the
&#8220;haystack&#8221;
We verify that both parameters were passed
We simply loop through the haystack checking for the needle
If we find it, return success.  Otherwise, eventually return
false


We need to loop through each server eventually, but we&#8217;ll start with
the first one

Run an SSH command to get a listing of builds
Populate an array ($CURRENT) with the builds that were found


Since the first server has no previous server to compare with, so we
just copy it to $MASTER


We then loop to the 2nd server, and put the result of getting builds
into $CURRENT

Now that we have the first server&#8217;s builds in $MASTER, we perform an
intersect with $CURRENT
We realize the need for an $INTERSECT array to hold the intersections
found above
$INTERSECT becomes $MASTER since it only contains similar builds from
the 1st and 2nd server


Looping to the 3rd server, we get the builds and put them in $CURRENT

Since $MASTER contains only the similar builds thus far, we again
compare it with $CURRENT
The intersect can now be used to compare against builds on the 4th
server, and so on


Once you finish looping through all servers, your $MASTER should
contain only similar builds

There are a few guides out there which show you how to do this via
forking, but I thought someone may appreciate the elegance of using 100%
bash to accomplish this.  I hope this helps someone else out there!]]></description>
			<content:encoded><![CDATA[<p>I am currently working on a project to deploy new website builds to a<br />
small number of servers.  I needed something simple and reliable that could<br />
be built in a very short period of time.  I decided to whip something up in<br />
bash with the intent of refining it in Python later.</p>
<p>As I began to write this code, I realized that it probably would have been<br />
quicker to do it in Python from the start.  I decided to stick with bash as<br />
somewhat of an academic exercise.  The vast majority of these deployment<br />
scripts were trivial; check the code out of git, create a manifest, package<br />
it up, spew it to the servers, etc, etc.  The problem came during the last<br />
step.  We decided to use a symlink to point to the active build out of a<br />
number of builds that could be available on the server at any given time.<br />
Since all of our servers should be running the exact same version of the<br />
build, it makes sense that I should only allow a user of my deployment<br />
scripts to link a build which exists on all servers.  But how do you<br />
accomplish this in bash?</p>
<p>In most other languages, you have access to numerous array helping<br />
functions that allow you to perform intersects, uniqs, and merges.  My goal<br />
was to do the same thing in bash without forking out to any external<br />
binary.  So how do you ensure that a particular thing exists on N number of<br />
servers?  Here it is:</p>
<pre lang="bash">function in_array() {
 local x
 ENTRY=$1
 shift 1
 ARRAY=( "$@" )
 [ -z "${ARRAY}" ] &amp;&amp; return 1
 [ -z "${ENTRY}" ] &amp;&amp; return 1
 for x in ${ARRAY[@]}; do
   [ "${x}" == "${ENTRY}" ] &amp;&amp; return 0
 done
 return 1
}

MASTER=()
CURRENT=()
FIRST=1
for SERVER in ${SERVERS}; do
 # collect all builds from server and populate CURRENT list
 COMMAND="${LS} -1fd ${WEBROOT}/${SITE}.*"
 BUILDS=`${SSH} ${SSHOPTS} root@${SERVER} "${COMMAND}"`
 for BUILD in ${BUILDS}; do
   CURRENT=( ${CURRENT[@]-} ${BUILD} )
 done

 # if this is our first time around, copy CURRENT to MASTER
 if [ ${FIRST} -eq 1 ]; then
   MASTER=( ${CURRENT[@]} )
   FIRST=0
 fi

 # now we do a compare between MASTER and CURRENT to see what builds
 # are common
 INTERSECT=()
 for ENTRY in ${CURRENT[@]}; do
   in_array "${ENTRY}" "${MASTER[@]}"
   RET=$?
   if [ "${RET}" -eq 0 ]; then
     INTERSECT=( ${INTERSECT[@]-} ${ENTRY} )
   fi
 done
 MASTER=( ${INTERSECT[@]} )

 # clear the CURRENT array
 CURRENT=()
done</pre>
<p>Let me take a moment to explain the code above:</p>
<ul>
<li> In order to check for array intersection, you need an in_array()<br />
function</p>
<ul>
<li>The first argument as the &#8220;needle&#8221; and the second is the<br />
&#8220;haystack&#8221;</li>
<li>We verify that both parameters were passed</li>
<li>We simply loop through the haystack checking for the needle</li>
<li>If we find it, return success.  Otherwise, eventually return<br />
false</li>
</ul>
</li>
<li>We need to loop through each server eventually, but we&#8217;ll start with<br />
the first one</p>
<ul>
<li>Run an SSH command to get a listing of builds</li>
<li>Populate an array ($CURRENT) with the builds that were found</li>
</ul>
<ul>
<li>Since the first server has no previous server to compare with, so we<br />
just copy it to $MASTER</li>
</ul>
</li>
<li>We then loop to the 2nd server, and put the result of getting builds<br />
into $CURRENT</p>
<ul>
<li>Now that we have the first server&#8217;s builds in $MASTER, we perform an<br />
intersect with $CURRENT</li>
<li>We realize the need for an $INTERSECT array to hold the intersections<br />
found above</li>
<li>$INTERSECT becomes $MASTER since it only contains similar builds from<br />
the 1st and 2nd server</li>
</ul>
</li>
<li>Looping to the 3rd server, we get the builds and put them in $CURRENT
<ul>
<li>Since $MASTER contains only the similar builds thus far, we again<br />
compare it with $CURRENT</li>
<li>The intersect can now be used to compare against builds on the 4th<br />
server, and so on</li>
</ul>
</li>
<li>Once you finish looping through all servers, your $MASTER should<br />
contain only similar builds</li>
</ul>
<p>There are a few guides out there which show you how to do this via<br />
forking, but I thought someone may appreciate the elegance of using 100%<br />
bash to accomplish this.  I hope this helps someone else out there!</p><br/>PlanetMySQL Voting:
	 <a href="http://planet.mysql.com/entry/vote/?entry_id=26269&vote=1&apivote=1">Vote UP</a> /
	 <a href="http://planet.mysql.com/entry/vote/?entry_id=26269&vote=-1&apivote=1">Vote DOWN</a>]]></content:encoded>
			<wfw:commentRss>http://planetmysql.ru/2010/10/26/bash-performing-array-intersection-with-bash/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>[Bash] Performing array intersection with Bash</title>
		<link>http://crazytoon.com/2010/10/25/bash-performing-array-intersection-with-bash/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=bash-performing-array-intersection-with-bash</link>
		<comments>http://crazytoon.com/2010/10/25/bash-performing-array-intersection-with-bash/#comments</comments>
		<pubDate>Tue, 26 Oct 2010 01:15:51 +0000</pubDate>
		<dc:creator>Sunny Walia</dc:creator>
				<category><![CDATA[bash]]></category>
		<category><![CDATA[CentOS]]></category>
		<category><![CDATA[Linux Apache MySQL PHP]]></category>
		<category><![CDATA[Linux System]]></category>
		<category><![CDATA[Linux Tips]]></category>

		<guid isPermaLink="false">http://crazytoon.com/?p=224</guid>
		<description><![CDATA[I am currently working on a project to deploy new website builds to a
small number of servers.  I needed something simple and reliable that could
be built in a very short period of time.  I decided to whip something up in
bash with the intent of refining it in Python later.
As I began to write this code, I realized that it probably would have been
quicker to do it in Python from the start.  I decided to stick with bash as
somewhat of an academic exercise.  The vast majority of these deployment
scripts were trivial; check the code out of git, create a manifest, package
it up, spew it to the servers, etc, etc.  The problem came during the last
step.  We decided to use a symlink to point to the active build out of a
number of builds that could be available on the server at any given time.
Since all of our servers should be running the exact same version of the
build, it makes sense that I should only allow a user of my deployment
scripts to link a build which exists on all servers.  But how do you
accomplish this in bash?
In most other languages, you have access to numerous array helping
functions that allow you to perform intersects, uniqs, and merges.  My goal
was to do the same thing in bash without forking out to any external
binary.  So how do you ensure that a particular thing exists on N number of
servers?  Here it is:
function in_array() {
 local x
 ENTRY=$1
 shift 1
 ARRAY=( "$@" )
 [ -z "${ARRAY}" ] &#38;&#38; return 1
 [ -z "${ENTRY}" ] &#38;&#38; return 1
 for x in ${ARRAY[@]}; do
   [ "${x}" == "${ENTRY}" ] &#38;&#38; return 0
 done
 return 1
}

MASTER=()
CURRENT=()
FIRST=1
for SERVER in ${SERVERS}; do
 # collect all builds from server and populate CURRENT list
 COMMAND="${LS} -1fd ${WEBROOT}/${SITE}.*"
 BUILDS=`${SSH} ${SSHOPTS} root@${SERVER} "${COMMAND}"`
 for BUILD in ${BUILDS}; do
   CURRENT=( ${CURRENT[@]-} ${BUILD} )
 done

 # if this is our first time around, copy CURRENT to MASTER
 if [ ${FIRST} -eq 1 ]; then
   MASTER=( ${CURRENT[@]} )
   FIRST=0
 fi

 # now we do a compare between MASTER and CURRENT to see what builds
 # are common
 INTERSECT=()
 for ENTRY in ${CURRENT[@]}; do
   in_array "${ENTRY}" "${MASTER[@]}"
   RET=$?
   if [ "${RET}" -eq 0 ]; then
     INTERSECT=( ${INTERSECT[@]-} ${ENTRY} )
   fi
 done
 MASTER=( ${INTERSECT[@]} )

 # clear the CURRENT array
 CURRENT=()
done
Let me take a moment to explain the code above:

 In order to check for array intersection, you need an in_array()
function

The first argument as the &#8220;needle&#8221; and the second is the
&#8220;haystack&#8221;
We verify that both parameters were passed
We simply loop through the haystack checking for the needle
If we find it, return success.  Otherwise, eventually return
false


We need to loop through each server eventually, but we&#8217;ll start with
the first one

Run an SSH command to get a listing of builds
Populate an array ($CURRENT) with the builds that were found


Since the first server has no previous server to compare with, so we
just copy it to $MASTER


We then loop to the 2nd server, and put the result of getting builds
into $CURRENT

Now that we have the first server&#8217;s builds in $MASTER, we perform an
intersect with $CURRENT
We realize the need for an $INTERSECT array to hold the intersections
found above
$INTERSECT becomes $MASTER since it only contains similar builds from
the 1st and 2nd server


Looping to the 3rd server, we get the builds and put them in $CURRENT

Since $MASTER contains only the similar builds thus far, we again
compare it with $CURRENT
The intersect can now be used to compare against builds on the 4th
server, and so on


Once you finish looping through all servers, your $MASTER should
contain only similar builds

There are a few guides out there which show you how to do this via
forking, but I thought someone may appreciate the elegance of using 100%
bash to accomplish this.  I hope this helps someone else out there!]]></description>
			<content:encoded><![CDATA[<p>I am currently working on a project to deploy new website builds to a<br />
small number of servers.  I needed something simple and reliable that could<br />
be built in a very short period of time.  I decided to whip something up in<br />
bash with the intent of refining it in Python later.</p>
<p>As I began to write this code, I realized that it probably would have been<br />
quicker to do it in Python from the start.  I decided to stick with bash as<br />
somewhat of an academic exercise.  The vast majority of these deployment<br />
scripts were trivial; check the code out of git, create a manifest, package<br />
it up, spew it to the servers, etc, etc.  The problem came during the last<br />
step.  We decided to use a symlink to point to the active build out of a<br />
number of builds that could be available on the server at any given time.<br />
Since all of our servers should be running the exact same version of the<br />
build, it makes sense that I should only allow a user of my deployment<br />
scripts to link a build which exists on all servers.  But how do you<br />
accomplish this in bash?</p>
<p>In most other languages, you have access to numerous array helping<br />
functions that allow you to perform intersects, uniqs, and merges.  My goal<br />
was to do the same thing in bash without forking out to any external<br />
binary.  So how do you ensure that a particular thing exists on N number of<br />
servers?  Here it is:</p>
<pre lang="bash">function in_array() {
 local x
 ENTRY=$1
 shift 1
 ARRAY=( "$@" )
 [ -z "${ARRAY}" ] &amp;&amp; return 1
 [ -z "${ENTRY}" ] &amp;&amp; return 1
 for x in ${ARRAY[@]}; do
   [ "${x}" == "${ENTRY}" ] &amp;&amp; return 0
 done
 return 1
}

MASTER=()
CURRENT=()
FIRST=1
for SERVER in ${SERVERS}; do
 # collect all builds from server and populate CURRENT list
 COMMAND="${LS} -1fd ${WEBROOT}/${SITE}.*"
 BUILDS=`${SSH} ${SSHOPTS} root@${SERVER} "${COMMAND}"`
 for BUILD in ${BUILDS}; do
   CURRENT=( ${CURRENT[@]-} ${BUILD} )
 done

 # if this is our first time around, copy CURRENT to MASTER
 if [ ${FIRST} -eq 1 ]; then
   MASTER=( ${CURRENT[@]} )
   FIRST=0
 fi

 # now we do a compare between MASTER and CURRENT to see what builds
 # are common
 INTERSECT=()
 for ENTRY in ${CURRENT[@]}; do
   in_array "${ENTRY}" "${MASTER[@]}"
   RET=$?
   if [ "${RET}" -eq 0 ]; then
     INTERSECT=( ${INTERSECT[@]-} ${ENTRY} )
   fi
 done
 MASTER=( ${INTERSECT[@]} )

 # clear the CURRENT array
 CURRENT=()
done</pre>
<p>Let me take a moment to explain the code above:</p>
<ul>
<li> In order to check for array intersection, you need an in_array()<br />
function</p>
<ul>
<li>The first argument as the &#8220;needle&#8221; and the second is the<br />
&#8220;haystack&#8221;</li>
<li>We verify that both parameters were passed</li>
<li>We simply loop through the haystack checking for the needle</li>
<li>If we find it, return success.  Otherwise, eventually return<br />
false</li>
</ul>
</li>
<li>We need to loop through each server eventually, but we&#8217;ll start with<br />
the first one</p>
<ul>
<li>Run an SSH command to get a listing of builds</li>
<li>Populate an array ($CURRENT) with the builds that were found</li>
</ul>
<ul>
<li>Since the first server has no previous server to compare with, so we<br />
just copy it to $MASTER</li>
</ul>
</li>
<li>We then loop to the 2nd server, and put the result of getting builds<br />
into $CURRENT</p>
<ul>
<li>Now that we have the first server&#8217;s builds in $MASTER, we perform an<br />
intersect with $CURRENT</li>
<li>We realize the need for an $INTERSECT array to hold the intersections<br />
found above</li>
<li>$INTERSECT becomes $MASTER since it only contains similar builds from<br />
the 1st and 2nd server</li>
</ul>
</li>
<li>Looping to the 3rd server, we get the builds and put them in $CURRENT
<ul>
<li>Since $MASTER contains only the similar builds thus far, we again<br />
compare it with $CURRENT</li>
<li>The intersect can now be used to compare against builds on the 4th<br />
server, and so on</li>
</ul>
</li>
<li>Once you finish looping through all servers, your $MASTER should<br />
contain only similar builds</li>
</ul>
<p>There are a few guides out there which show you how to do this via<br />
forking, but I thought someone may appreciate the elegance of using 100%<br />
bash to accomplish this.  I hope this helps someone else out there!</p><br/>PlanetMySQL Voting:
	 <a href="http://planet.mysql.com/entry/vote/?entry_id=26269&vote=1&apivote=1">Vote UP</a> /
	 <a href="http://planet.mysql.com/entry/vote/?entry_id=26269&vote=-1&apivote=1">Vote DOWN</a>]]></content:encoded>
			<wfw:commentRss>http://planetmysql.ru/2010/10/26/bash-performing-array-intersection-with-bash/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Easy MySQL: how to backup databases to a remote machine</title>
		<link>http://feedproxy.google.com/~r/Themattreid/~3/vrMwJDwqbr0/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=easy-mysql-how-to-backup-databases-to-a-remote-machine</link>
		<comments>http://feedproxy.google.com/~r/Themattreid/~3/vrMwJDwqbr0/#comments</comments>
		<pubDate>Fri, 13 Aug 2010 21:27:39 +0000</pubDate>
		<dc:creator>Matt Reid</dc:creator>
				<category><![CDATA[Backups]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[mysql server]]></category>
		<category><![CDATA[mysqldump]]></category>
		<category><![CDATA[scp]]></category>
		<category><![CDATA[Scripting]]></category>
		<category><![CDATA[scripts]]></category>
		<category><![CDATA[solaris]]></category>
		<category><![CDATA[ssh]]></category>

		<guid isPermaLink="false">http://themattreid.com/wordpress/?p=335</guid>
		<description><![CDATA[Here&#8217;s a simple answer to a simple question. &#8220;How do I run a backup of MySQL to another machine without writing to the local server&#8217;s filesystem?&#8221; &#8211; this is especially useful if you are running out of space on the local server and cannot write a temporary file to the filesystem during backups. 
Method one &#8211; this writes a remote file.
mysqldump [options] [db_name&#124;--all-databases]&#124; gzip -c &#124; ssh user@host.com "cat &#62; /path/to/new/file.sql.gz"
Method two &#8211; this writes directly into a remote mysql server
mysqldump [options] [db_name&#124;--all-databases]&#124; mysql --host=[remote host] –user=root –password=[pass] [db_name]
]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s a simple answer to a simple question. &#8220;How do I run a backup of MySQL to another machine without writing to the local server&#8217;s filesystem?&#8221; &#8211; this is especially useful if you are running out of space on the local server and cannot write a temporary file to the filesystem during backups. </p>
<p>Method one &#8211; this writes a remote file.<br />
<code>mysqldump [options] [db_name|--all-databases]| gzip -c | ssh user@host.com "cat > /path/to/new/file.sql.gz"</code></p>
<p>Method two &#8211; this writes directly into a remote mysql server<br />
<code>mysqldump [options] [db_name|--all-databases]| mysql --host=[remote host] –user=root –password=[pass] [db_name]</code></p>
<img src="http://feeds.feedburner.com/~r/Themattreid/~4/vrMwJDwqbr0" height="1" width="1" /><br/>PlanetMySQL Voting:
	 <a href="http://planet.mysql.com/entry/vote/?entry_id=25560&vote=1&apivote=1">Vote UP</a> /
	 <a href="http://planet.mysql.com/entry/vote/?entry_id=25560&vote=-1&apivote=1">Vote DOWN</a>]]></content:encoded>
			<wfw:commentRss>http://planetmysql.ru/2010/08/14/easy-mysql-how-to-backup-databases-to-a-remote-machine/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to: rotate wordpress posts into headline/feature status</title>
		<link>http://feedproxy.google.com/~r/Themattreid/~3/kxeJcFESJ20/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=how-to-rotate-wordpress-posts-into-headlinefeature-status</link>
		<comments>http://feedproxy.google.com/~r/Themattreid/~3/kxeJcFESJ20/#comments</comments>
		<pubDate>Sun, 08 Aug 2010 00:16:55 +0000</pubDate>
		<dc:creator>Matt Reid</dc:creator>
				<category><![CDATA[automation]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[mysql server]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[Scripting]]></category>
		<category><![CDATA[scripts]]></category>
		<category><![CDATA[Wordpress]]></category>

		<guid isPermaLink="false">http://themattreid.com/wordpress/?p=323</guid>
		<description><![CDATA[If you&#8217;re using the new Arthemia theme for WordPress you might notice that there are two areas of the theme that can have articles promoted to; namely Headline and Featured sections. This is controlled by category association. Basically you have a post and if you want it in the Headline area of the theme you attach the category &#8220;headline&#8221; to it, similarly for the featured section. Now, let&#8217;s say you don&#8217;t want to manually change this all the time since it can be time consuming to promote posts to those categories if you want rotating content.
Here&#8217;s a simple solution. In this bash script I connect to MySQL and remove the current associations from posts and then randomly choose posts to be promoted to the Headline and Featured categories. This can be modified for other ideas you might have involving categories/posts/randomized associations in WordPress. You can also find the script here: http://pastebin.com/1QqiM5rh &#8211; wordpress is clobbering my line breaks so use the Pastebin version if you want to copy/paste the content. 
The queries contain IDs for the Headline and Featured categories. In my installation, which will be different than yours, has the Headline category as ID=&#8217;103&#8242; and Featured as ID=&#8217;104&#8242; &#8211; replace as needed. I&#8217;m also doing some matching (see the WHERE sections) so that I don&#8217;t promote posts with certain IDs that are specific to the site for this script. You&#8217;ll want to customize the queries as needed for your site. 
#!/bin/bash
#wordpress connection settings
USER="wordpress"
PASSWORD="password"
HOST="mysql.mysite.com"
DB="wordpress"
MYSQL="/usr/bin/mysql"
#remove current relationship for headline/post, set random post as headline
HEADLINE0="DELETE FROM wp_term_relationships WHERE term_taxonomy_id='103'; INSERT INTO wp_term_relationships (object_id,term_taxonomy_id,term_order) VALUES ((select ID from wp_posts where post_name NOT LIKE '%autosave%' AND post_name != '' and post_name !='hello-world' AND ID !='2' AND ID !='16' AND ID !='35' AND ID !='44' ORDER BY RAND() LIMIT 1),'103','0');"
#select current headline post - for reference, we never use this in the script
HEADLINE1="select * from wp_term_relationships where term_taxonomy_id = '103';"
#remove current relationship for featured/post, set random post as featured
FEATURED0="DELETE FROM wp_term_relationships WHERE term_taxonomy_id='104'; INSERT INTO wp_term_relationships (object_id,term_taxonomy_id,term_order) VALUES
((select ID from wp_posts where post_name NOT LIKE '%autosave%' AND post_name != '' and post_name !='hello-world' AND ID !='2' AND ID !='16' AND ID !='35' AND ID !='44' ORDER BY RAND() LIMIT 1),'104','0'),
((select ID from wp_posts where post_name NOT LIKE '%autosave%' AND post_name != '' and post_name !='hello-world' AND ID !='2' AND ID !='16' AND ID !='35' AND ID !='44' ORDER BY RAND() LIMIT 1),'104','0'),
((select ID from wp_posts where post_name NOT LIKE '%autosave%' AND post_name != '' and post_name !='hello-world' AND ID !='2' AND ID !='16' AND ID !='35' AND ID !='44' ORDER BY RAND() LIMIT 1),'104','0'),
((select ID from wp_posts where post_name NOT LIKE '%autosave%' AND post_name != '' and post_name !='hello-world' AND ID !='2' AND ID !='16' AND ID !='35' AND ID !='44' ORDER BY RAND() LIMIT 1),'104','0'),
((select ID from wp_posts where post_name NOT LIKE '%autosave%' AND post_name != '' and post_name !='hello-world' AND ID !='2' AND ID !='16' AND ID !='35' AND ID !='44' ORDER BY RAND() LIMIT 1),'104','0');"
#execute queries
echo -n "Updating headline: "
until $MYSQL --user="$USER" --password="$PASSWORD" --host="$HOST" "$DB" -e "$HEADLINE0"; do
    echo "[FAILED]"
    echo -n "Running again: "
done
echo "[OK]"
echo -n "Updating featured: "
until $MYSQL --user="$USER" --password="$PASSWORD" --host="$HOST" "$DB" -e "$FEATURED0"; do
echo "[FAILED]"
    echo -n "Running again: "
done
echo "[OK]"

]]></description>
			<content:encoded><![CDATA[<p>If you&#8217;re using the new <a href="http://www.themelab.com/2008/08/26/arthemia-wordpress-theme-review/" >Arthemia theme</a> for WordPress you might notice that there are two areas of the theme that can have articles promoted to; namely Headline and Featured sections. This is controlled by category association. Basically you have a post and if you want it in the Headline area of the theme you attach the category &#8220;headline&#8221; to it, similarly for the featured section. Now, let&#8217;s say you don&#8217;t want to manually change this all the time since it can be time consuming to promote posts to those categories if you want rotating content.</p>
<p>Here&#8217;s a simple solution. In this bash script I connect to MySQL and remove the current associations from posts and then randomly choose posts to be promoted to the Headline and Featured categories. This can be modified for other ideas you might have involving categories/posts/randomized associations in WordPress. You can also find the script here: <a href="http://pastebin.com/1QqiM5rh">http://pastebin.com/1QqiM5rh</a> &#8211; wordpress is clobbering my line breaks so use the Pastebin version if you want to copy/paste the content. </p>
<p>The queries contain IDs for the Headline and Featured categories. In my installation, which will be different than yours, has the Headline category as ID=&#8217;103&#8242; and Featured as ID=&#8217;104&#8242; &#8211; replace as needed. I&#8217;m also doing some matching (see the WHERE sections) so that I don&#8217;t promote posts with certain IDs that are specific to the site for this script. You&#8217;ll want to customize the queries as needed for your site. </p>
<p><code>#!/bin/bash<br />
#wordpress connection settings<br />
USER="wordpress"<br />
PASSWORD="password"<br />
HOST="mysql.mysite.com"<br />
DB="wordpress"<br />
MYSQL="/usr/bin/mysql"<br />
#remove current relationship for headline/post, set random post as headline<br />
HEADLINE0="DELETE FROM wp_term_relationships WHERE term_taxonomy_id='103'; INSERT INTO wp_term_relationships (object_id,term_taxonomy_id,term_order) VALUES ((select ID from wp_posts where post_name NOT LIKE '%autosave%' AND post_name != '' and post_name !='hello-world' AND ID !='2' AND ID !='16' AND ID !='35' AND ID !='44' ORDER BY RAND() LIMIT 1),'103','0');"<br />
#select current headline post - for reference, we never use this in the script<br />
HEADLINE1="select * from wp_term_relationships where term_taxonomy_id = '103';"<br />
#remove current relationship for featured/post, set random post as featured<br />
FEATURED0="DELETE FROM wp_term_relationships WHERE term_taxonomy_id='104'; INSERT INTO wp_term_relationships (object_id,term_taxonomy_id,term_order) VALUES<br />
((select ID from wp_posts where post_name NOT LIKE '%autosave%' AND post_name != '' and post_name !='hello-world' AND ID !='2' AND ID !='16' AND ID !='35' AND ID !='44' ORDER BY RAND() LIMIT 1),'104','0'),<br />
((select ID from wp_posts where post_name NOT LIKE '%autosave%' AND post_name != '' and post_name !='hello-world' AND ID !='2' AND ID !='16' AND ID !='35' AND ID !='44' ORDER BY RAND() LIMIT 1),'104','0'),<br />
((select ID from wp_posts where post_name NOT LIKE '%autosave%' AND post_name != '' and post_name !='hello-world' AND ID !='2' AND ID !='16' AND ID !='35' AND ID !='44' ORDER BY RAND() LIMIT 1),'104','0'),<br />
((select ID from wp_posts where post_name NOT LIKE '%autosave%' AND post_name != '' and post_name !='hello-world' AND ID !='2' AND ID !='16' AND ID !='35' AND ID !='44' ORDER BY RAND() LIMIT 1),'104','0'),<br />
((select ID from wp_posts where post_name NOT LIKE '%autosave%' AND post_name != '' and post_name !='hello-world' AND ID !='2' AND ID !='16' AND ID !='35' AND ID !='44' ORDER BY RAND() LIMIT 1),'104','0');"<br />
#execute queries<br />
echo -n "Updating headline: "<br />
until $MYSQL --user="$USER" --password="$PASSWORD" --host="$HOST" "$DB" -e "$HEADLINE0"; do<br />
    echo "[FAILED]"<br />
    echo -n "Running again: "<br />
done<br />
echo "[OK]"<br />
echo -n "Updating featured: "<br />
until $MYSQL --user="$USER" --password="$PASSWORD" --host="$HOST" "$DB" -e "$FEATURED0"; do<br />
echo "[FAILED]"<br />
    echo -n "Running again: "<br />
done<br />
echo "[OK]"<br />
</code></p>
<img src="http://feeds.feedburner.com/~r/Themattreid/~4/kxeJcFESJ20" height="1" width="1" /><br/>PlanetMySQL Voting:
	 <a href="http://planet.mysql.com/entry/vote/?entry_id=25504&vote=1&apivote=1">Vote UP</a> /
	 <a href="http://planet.mysql.com/entry/vote/?entry_id=25504&vote=-1&apivote=1">Vote DOWN</a>]]></content:encoded>
			<wfw:commentRss>http://planetmysql.ru/2010/08/08/how-to-rotate-wordpress-posts-into-headlinefeature-status/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>N900 &#8211; control all of your accounts with this script</title>
		<link>http://feedproxy.google.com/~r/Themattreid/~3/q9pWVZOsDxg/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=n900-control-all-of-your-accounts-with-this-script</link>
		<comments>http://feedproxy.google.com/~r/Themattreid/~3/q9pWVZOsDxg/#comments</comments>
		<pubDate>Tue, 27 Jul 2010 22:42:27 +0000</pubDate>
		<dc:creator>Matt Reid</dc:creator>
				<category><![CDATA[bash]]></category>
		<category><![CDATA[instant messenger]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[N900]]></category>
		<category><![CDATA[opensource]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[Scripting]]></category>

		<guid isPermaLink="false">http://themattreid.com/wordpress/?p=321</guid>
		<description><![CDATA[If you own a Nokia N900 cellular device you might be interested in the ability to control all of your IM accounts from the command line. For those that do not know, the N900 runs Maemo Linux and is capable of running MySQL embedded if you so choose. Here&#8217;s a quick script I wrote to provide that functionality for IM accounts. It&#8217;s at the bottom of the page, called &#8220;im-connections&#8221;.
wiki: http://wiki.maemo.org/N900_Mission_Control#Set_all_SIP_accounts_to_online_or_offline
pastebin: http://pastebin.com/qAC57E1N
]]></description>
			<content:encoded><![CDATA[<p>If you own a Nokia N900 cellular device you might be interested in the ability to control all of your IM accounts from the command line. For those that do not know, the N900 runs Maemo Linux and is capable of running MySQL embedded if you so choose. Here&#8217;s a quick script I wrote to provide that functionality for IM accounts. It&#8217;s at the bottom of the page, called &#8220;im-connections&#8221;.</p>
<p>wiki: <a title="http://wiki.maemo.org/N900_Mission_Control#Set_all_SIP_accounts_to_online_or_offline" href="http://wiki.maemo.org/N900_Mission_Control#Set_all_SIP_accounts_to_online_or_offline" >http://wiki.maemo.org/N900_Mission_Control#Set_all_SIP_accounts_to_online_or_offline</a><br />
pastebin: <a title="http://pastebin.com/qAC57E1N" href="http://pastebin.com/qAC57E1N" >http://pastebin.com/qAC57E1N</a></p>
<img src="http://feeds.feedburner.com/~r/Themattreid/~4/q9pWVZOsDxg" height="1" width="1" /><br/>PlanetMySQL Voting:
	 <a href="http://planet.mysql.com/entry/vote/?entry_id=25409&vote=1&apivote=1">Vote UP</a> /
	 <a href="http://planet.mysql.com/entry/vote/?entry_id=25409&vote=-1&apivote=1">Vote DOWN</a>]]></content:encoded>
			<wfw:commentRss>http://planetmysql.ru/2010/07/28/n900-control-all-of-your-accounts-with-this-script/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

