By user12622652 on Mar 02, 2009
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.