TwitterMQ?


This weekend I have been busy deploying Bacula as a backup solution for my Solaris media server at home. Bacula itself is pretty easy to set up and configure. The installation was a breeze. I just used the Blastwave package manager and had the installation done very quickly. The configuration took a little more time, but the documentation is pretty good.


My biggest challenge was configuring email notifications so that I know when my backups are running and so that I know the status. Ideally, I would like to get notifications sent to an account that I have access to on my phone. My ISP has disabled port 25 on my cable modem, so I am not able to send email using a tradition mail relay. I looked into getting authenticated email working over port 587 using my credentials, but getting that to work seemed cumbersome. I looked into using swaks, but to make it secure requires some Perl OpenSSO packages that I wasn't able to get working.


Twitter turns out to be a pretty good solution for this. I simply set up two Twitter accounts to handle the publisher/subscriber model. The Publisher account receives the updates from my backup server. The subscriber is on the notification list for the publisher account. I have also configured SMS notifications on the subscriber account so that these messages are sent to my phone.

The cool part is that Bacula's email configuration is just a simple command line operation.


I wrote a Java application that takes the place of the default bsmtp application that comes with Bacula. The Java application accepts command line arguments for the subscriber's Twitter credentials. It also has an argument for the subject of the message. Bacula sends the rest of the notification information to standard input.

The Java application relies on some pretty nifty libraries to handle the core operations. I used JTwitter for handling the interactions with Twitter. I also used the Apache Commons IO library to simplify reading data from standard in. Twitter only allows 160 characters per message, so I needed to parse the data from Bacula. I was only really interested in a few key fields: Number of Files, Number of Bytes, and Elapsed Time. The Java package java.util.regex came to the rescue. I was able to configure some simple regular expressions that find the data I am looking for. The rest of the code just formats the messages and updates the publisher's status on Twitter. 


Here is what the command line entry looks line in the bacula-dir.conf configuration file:


mailcommand = "java -cp jtwitter.jar:commons-io-1.4.jar:TwitterCLI.jar twittercli.Main twitter_publisher_acct password \\"Bacula: %t %n %e of %c %l\\" false"


operatorcommand = "java -cp jtwitter.jar:commons-io-1.4.jar:TwitterCLI.jar twittercli.Main twitter_publisher_acct password \\"Bacula: %t %n %e of %c %l\\" false" 


Now I have exactly what I was after.  Bacula is a free backup solution that handles full, differential, and incremental operations.  It also runs on a schedule and can send out notifications to my phone so that I am aware of the backup status.  Using Twitter for the updates works great.  I can definitely see potential for other uses like this.

Comments:

Hi,
very interesting..
Likewise you I need to send the information of every backup to a collector, but I don't understand how you have done to read the standard input, to send the addition information as you have done:
Number of Files, Number of Bytes, and Elapsed Time.

Thank yoi

Posted by Carlo on November 08, 2012 at 09:27 AM MST #

Carlo,

I have made some changes to this script since I wrote this post. For one thing, Twitter now requires OAuth in order to send updates to an account. I have since replaced the JTwitter library with twitter4j. The nice thing is that twitter4j comes with a sample script in bin/tweets/updateStatus.sh. This script sends whatever is supplied on the command line as a message to Twitter. I also simplified my backup to just use tar and copy everything to an external USB drive. So, there is no need to stdin. I just call updateStatus.sh with a pass/fail and a timestamp when the script completes.

Jim

Posted by Jim on November 08, 2012 at 10:26 PM MST #

Post a Comment:
  • HTML Syntax: NOT allowed
About

user12622652

Search

Categories
Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today