Tuesday, September 22, 2009

directory monitor dnotify

Yesterday a copier was installed in the company network. The machine could do a scan-to-FTP. So on the local debianbox I set up vsftpd. I wanted to change the permissions of each new scan that was made, so other users could use it as well. Instead of fiddling with the vsftpd config, I tested dnotify. It's a very small utility, very simple but very usefull. You can monitor a directory for changes, new files, deleted files, ... and add a command to execute upon one of these events.
For example: dnotify -b -C /share/scan -e chmod -R 0777 /share/scan
Everytime a new file is created in /share/scan it will set the permission.
-b tells it to run in background.

Tuesday, July 7, 2009

minimal X server/windowmanager

To install X server from a minimal Debian install and make it start on boot:
apt-get install xserver-xorg
apt-get install fluxbox (for example)
apt-get install xinit
put "su -c /usr/bin/X11/startx " in your /etc/rc.local
Make sure the user can start X. Therefor you might have to edit /etc/X11/Xwrapper.config and use: allowed_users=anybody

Monday, July 6, 2009

managing startup processes

Untill today I thought managing startup processes and it's corresponding runlevels were a bit cumbersome. I used (well, I still actually) RedHat based distros, and they had the nice little utility called ntsysv. You can select what programs to run by means of a simple text gui. Thanks to Amoena's blog, I discovered sysv-rc-conf! Check it out!

Tuesday, February 17, 2009

backup up a dozen of windows PC's

There are many backup solutions out there. To get a second copy of all windows clients you could install software on each PC like Cobian, Mirrorfolder or Viceversa. And then let the data copy to a fileserver somewhere in the network. This works fine for a single PC, but if you have more than ten clients to configure, it gets quite hard to maintain.
I wanted a solution with the following features:
- centralized management of directories to backup and schedule.
- automated backup
- minimal software on the windows PC
- open source

What I did:
Installed Deltacopy on the windows PC's. This is basically a rsync server with a GUI. I created one big "rsync-share" which is the C: drive.
On the linux fileserver (a nslu2 with a big usb disk) I wrote some small scripts.
Here is an example:

#!/bin/bash

BCKHOST=mylaptop
HOSTUSER=backup
HOSTPASSFILE=/root/backup/passw/$BCKHOST
RSYNCPARMS="-avtol --stats --bwlimit=200 --delete"
DESTDIR=/home/share/deltacopy
SRCDIR1=/c_drive/DOCS
BCKLOG=/var/log/deltacopy/$BCKHOST.log


chmod 600 $HOSTPASSFILE

while test 1
do
while ! ping -c1 -w4 $BCKHOST > /dev/null
do
sleep 300
done
echo "DELTACOPY -- [`date`] $BCKHOST is up" >> $BCKLOG

sleep 200

echo "DELTACOPY -- [`date`] starting backup on $BCKHOST" >> $BCKLOG

rsync $RSYNCPARMS --password-file=$HOSTPASSFILE rsync://$HOSTUSER@$BCKHOST$SRCDIR1 $DESTDIR/$BCKHOST 1>> $BCKLOG 2>> $BCKLOG

echo "DELTACOPY -- [`date`] backup finished" >> $BCKLOG

while ping -c1 -w5 $BCKHOST > /dev/null
do
sleep 300
done
echo "DELTACOPY -- [`date`] $BCKHOST is down" >> $BCKLOG
done


For each host you'll have to make a copy of this script.
The script waits until the PC is on the network and then starts the rsync backup. When finished it waits until it's powered off. Then the scripts starts over again. At night a second script takes care of email notification, here it is:

#!/bin/bash

# usage: sendreport

REPORT=/var/log/deltacopy/$1.log
RECIPIENT=$2
DATESTAMP=`date | cut -b 1-10`

if [ ! -f $REPORT ]; then
SUBJECT="[$HOSTNAME] - MISSING backup for $1 on $DATESTAMP"
else
if ( `grep -q "rsync" $REPORT` || `grep -q "fail" $REPORT`); then
SUBJECT="[$HOSTNAME] - FAILED backup for $1 on $DATESTAMP"
else SUBJECT="[$HOSTNAME] - SUCCESSFUL backup for $1 on $DATESTAMP"
fi
fi

cat $REPORT | mail -s"$SUBJECT" $RECIPIENT


Et voila... simple and reliable.
Feel free to comment.

Baobab

What!? indeed: baobab. A colleage of mine told me this was some kind of remarkable tree, but it also turns out to be a little handy utlility.
With baobab you'll get a nice overview of all the directory sizes. You can also let this utility connect to a remote filesystem. The sector view is a bit akward at first but it's quite convenient. Requires gnome. An apt-get install shows that the package is to be replaced by gnome-utils, so chances are it's already on your linux box.