Weekly backups of all OpenVZ container
Thu, 01/08/2009 - 17:56 — sandipHere's is a simple shell script to run a weekly lvm snapshot dump of all OpenVZ containers using the vzdump utility:
#!/bin/bash
# ve_dumps.sh
# Dump all VEs
# Todays' date
DATE=$(date +%d)
# Paths
BAK_PATH=/opt/bak/vz_dumpsr /># Week of month
BAK_DIR=$(cal | awk -v date="${DATE}" '{ for( i=1; i <= NF ; i++ ) if ($i==date) { print FNR-2 } }')
# Function to check and remove previously failed snapshot.
check_vzsnap() {
OUTPUT=`/usr/sbin/lvdisplay | grep vzsnap`
[ -n "$OUTPUT" ] && lvremove -f /dev/vg0/vzsnap
}
# Function to perform backup.
backup() {
# Check and create the required backup directory
[ -d "${BAK_PATH}/${BAK_DIR}&q uot; ] || mkdir -p ${BAK_PATH}/${BAK_DIR}
# do dumps
echo "Starting dump at `date`"
/usr/bin/vzdump --exclude-path '.+/log/.+' --exclude-path '.+/bak/.+' --exclude-path '/tmp/.+' --exclude-path '/var/tmp/.+' --exclude-path '/var/run/.+pid' --snapshot --dumpdir=${BAK_PATH}/${BAK_DI R} --compress --all
echo "Completed dump at `date`"
}
# Main ############################r />
# Remove previously failed snapshot
check_vzsnap
# Run backups
backup
exit 0
Week of Month
Thu, 01/08/2009 - 10:24 — sandipHere is a simple one liner to get the week of month via awk from a `cal` output:
$ cal | awk -v date="`date +%d`" '{ for( i=1; i <= NF ; i++ ) if ($i==date) { print FNR-2} }'
Verifying SSH Key Fingerprint
Thu, 01/01/2009 - 21:02 — sandipIf you've been given a public ssh host key and want to verify it before adding it permanently to your ssh known_hosts file:
Get the public ssh key:
$ ssh-keyscan -p 22 -t rsa,dsa {remote_host} > /tmp/ssh_host_rsa_dsa_key.pub
Get the ssh key fingerprint:
$ ssh-keygen -l -f /tmp/ssh_host_rsa_dsa_key.pub
Plesk root email delivery
Tue, 12/30/2008 - 02:23 — sandipTo receive local root email to an externally monitored email address:
-
Login to plesk control panel and set the admin contact email address for the server which should update "/var/qmail/alias/.qmail-root"
Either add the hostname (FQDN) to the qmail control locals file or to the virtualdomains file located in "/var/qmail/control/".
Also add the hostname (FQDN) to the "/var/qmail/control/rcpthosts"
Restart inetd and qmail:
/etc/init.d/inetd restart
/etc/init.d/qmail restart
/var/qmail/bin/qmail-showctl
This should show:
...
locals:
...
Messages for host.domain.tl are delivered locally.
...
rcpthosts:
...
SMTP clients may send messages to recipients at host.domain.tld.
...
Munin-node Plugin Configurations
Thu, 12/25/2008 - 00:50 — sandipHDD Temperature
You can usually identify which hard disks are on your system by looking in "/proc/ide" and in "/proc/scsi".
# cat /proc/scsi/scsi
Attached devices:
Host: scsi0 Channel: 00 Id: 00 Lun: 00
Vendor: ATA &nb sp; Model: WDC WD2500YS-01S Rev: 20.0
Type: Direct-Access   ;   ;   ;   ; ANSI SCSI revision: 05
Host: scsi1 Channel: 00 Id: 00 Lun: 00
Vendor: ATA &nb sp; Model: WDC WD2500YS-01S Rev: 20.0
Type: Direct-Access   ;   ;   ;   ; ANSI SCSI revision: 05
`fdisk -l` lists the two drives as "sda" and "sdb".
Drupal 5.14 upgrade fixes
Wed, 12/24/2008 - 00:37 — sandipWith the upgrade to drupal-5.14 and using the SecurePages 5.x-1.7-beta1 module:
Error:
PHP Fatal error: Call to undefined function drupal_urlencode() in /path/to/drupal/sites/all/modu les/securepages/securepages.mo dule on line 323
Solution:
Added the below code to the beginning of the securepages_init function in "securepages.module" so function gets loaded.
if (!function_exists('drupal
_urlencode')) {
include_once 'includes/common.inc';;
}Reference:
http://drupal.org/node/330171
highlight grep search string
Fri, 12/19/2008 - 15:09 — sandipDefault to highlighting search string when using grep by adding the below alias to ~/.bashrc file:
alias grep='grep --color=auto'
Share screen session
Tue, 12/16/2008 - 23:45 — sandip-
Start screen using the command:
$ screen -S <SessionName>
The -S switch gives the session a name, which makes multiple screen sessions easier to manage.
Allow multiuser access in the screen session:CTRL-A
:multiuser on
CTRL-A
:acladd <guest_user>
$ screen -x <host_user>/<SessionN ame>
c-client library version skew with uw-imap
Mon, 11/17/2008 - 11:30 — sandipWith the recent update of uw-imap from epel repository to uw-imap-2007d-1.el5, I was getting the below error which indicated that uw-imap required 2007d version of c-client.
Below was the error message as logged in "/var/log/messages":
IMAP toolkit crash: c-client library version skew, app=2007d library=2007b
Adding "libc-client2007" to the list of "includepkgs" in yum conf for epel repository and doing a `yum update` resolved the issue by updating libc-client2007-2007b to libc-client2007-2007d.
Convert / root filesytem to use lvm over raid
Sat, 11/01/2008 - 16:57 — sandipI have outlined below the steps taken to move from a normal single disk system and convert to a raid1 using an additional drive:
Note: /boot cannot be on lvm nor any other raids other than raid1 partition.
Don't forget to make the essential backups prior.
Convert / to raid/lvm
-
fdisk /dev/sdb and make clone of sda (convert partition type to "Linux raid autodetect")
add /dev/sdb1 -- /boot - 13 blocks (100Mb) - type raid
add /dev/sdb2 -- rest - type raid
Create raid partitions:
partprobe
mdadm -C /dev/md0 --auto=yes -l 1 -n 2 missing /dev/sdb1
mdadm -C /dev/md1 --auto=yes -l 1 -n 2 missing /dev/sdb2
pvcreate /dev/md1
vgcreate vg0 /dev/md1
lvcreate -L 4G -n lv0 vg0
mke2fs -j /dev/vg0/lv0
mkdir /mnt/lv0
mount /dev/vg0/lv0 /mnt/lv0
find / -xdev | cpio -pvmd /mnt/lv0
cp -aux /dev /mnt/lv0
/dev/vg0/lv0 /   ;   ;   ;   ; ext3 defaults &nbs p; 1 1
mount --bind /dev /mnt/lv0/dev
chroot /mnt/lv0
mount -t proc /proc /proc
mount -t sysfs /sys /sys
vgscan
vgchange -ay
mkinitrd -v /boot/initrd-`uname -r`.lvm.img `uname -r`
umount /sys
umount /proc
exit
mv /mnt/lv0/boot/initrd-`uname -r`.lvm.img /boot
reboot