miércoles 10 de noviembre de 2010

Bacula Migration Job

At work I have been configuring Bacula to backup our servers. Bacula will suck the essence from our servers at 1am and back everything up into disk volumes, then these volumes will be migrated to DAT160 tapes.

The process of backing up to disk volumes consisted in the simple definition of Jobs, FileSets and Schedules, in other words: what to backup, where and when.

The process of moving Jobs from disk volumes into tape volumes is called 'Migration', this is done with a 'Migrate' type Job.

Job {

    Name = Something
    Type = Migrate
    Pool = HardDisk
    Selection Type = SQLQuery
    Selection Pattern = "SELECT JobId from Job ..."

}

The thing with the Migrate type is that you can apply the options 'Selection Type' and 'Selection Pattern' to let Bacula choose wich Jobs should be migrated.

Selection Type lets you choose what type of selection will be applied and Selection Pattern provides a way to filter Jobs from the list generated by the Selection Type used.

My needs: I needed a Job that would migrate into tape volumes all the Jobs from the last day, this way I am sure that if I miss a migration the next day those skipped Jobs won't be migrated, I'll have to manually migrate them if needed. This behavior was intended because if a migration is skipped I am sure that the next day the skipped Jobs won't try to be migrated causing a possible abort because of max wait times.

The 'Selection Type' I used was: SQLQuery

Selection Type = SQLQuery

And the Selection Pattern is where we specify a valid SQL Query wich should return a list of JobId's. These Jobs are the ones that'll be Migrated.

Selection Pattern = "SELECT JobId FROM Job WHERE (RealEndTime > ADDDATE(CURDATE(),-1) AND PoolId=5 AND (JobStatus='T' OR JobStatus='E') AND Type='B')"

In my case the id of my Hard Disk pool is 5 so I filter with PoolId=5 to select jobs only in the Hard Disk pool.

JobStatus = T | E specifies to select Jobs succesfully performed (T) and Jobs that result succesful but contained some errors (E)

Type = 'B' indicates that I select Jobs of type 'Backup'

RealEndTime > ADDDATE(CURDATE(),-1) This part makes possible to filter and select only the Jobs that were finished the past day. So CURDATE() has the actual date and with ADDDATE(CURDATE(),-1) I get the date from the past day.

More info on Selection Types can be found at bacula documentation [1]


[1]: http://www.bacula.org/manuals/en/concepts/concepts/Migration_Copy.html

domingo 17 de octubre de 2010

SSH Login & libnotify

Lil' script I put up to show a notification using libnotify. It'll show a popup when SSH registers a login attemp wheter it fails or suceeds.

I think it may be useful in my notebook to monitor strange activity.

Examples:















The script:

tail -n0 -f /var/log/auth.log |egrep --line-buffered -e 'Failed|Accepted'|while read line
do

notify-send "SSH" "${line#*]:*}" -i /usr/share/pixmaps/gksu-root-terminal.png

done