sandip's blog

Weekly backups of all OpenVZ container

Here'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_dumps
# 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}" ] || 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_DIR} --compress --all
  echo "Completed dump at `date`"
}

# Main ############################

# Remove previously failed snapshot
check_vzsnap

# Run backups
backup

exit 0

Week of Month

Here 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

If 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

To 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" file and add an alias for 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" file if not already present so local mails get delivered.
  • Restart inetd and qmail:
    /etc/init.d/inetd restart
    /etc/init.d/qmail restart
  • Check with:
    /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

HDD 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      Model: WDC WD2500YS-01S Rev: 20.0
  Type:   Direct-Access                    ANSI SCSI revision: 05
Host: scsi1 Channel: 00 Id: 00 Lun: 00
  Vendor: ATA      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

With 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/modules/securepages/securepages.module 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

Default to highlighting search string when using grep by adding the below alias to ~/.bashrc file:

alias grep='grep --color=auto'

Share screen session

  1. Start screen using the command:

    $ screen -S <SessionName>

    The -S switch gives the session a name, which makes multiple screen sessions easier to manage.

  2. Allow multiuser access in the screen session:

    CTRL-A
    :multiuser on

  3. Grant permission to the guest user to access the screen session:

    CTRL-A
    :acladd <guest_user>

  4. The guest user can now connect via:

    $ screen -x <host_user>/<SessionName>

c-client library version skew with uw-imap

With 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

I 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

  1. fdisk /dev/sdb and make clone of sda (convert partition type to "Linux raid autodetect")
  2. add /dev/sdb1 -- /boot - 13 blocks (100Mb) - type raid
  3. add /dev/sdb2 -- rest - type raid
  4. 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
  5. Create logical volume and copy / partition and /dev files over:
    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
  6. Edit /mnt/lv0/etc/fstab to reflect the new root
    /dev/vg0/lv0            /                       ext3    defaults        1 1
  7. Chroot to new filesystem and create initrd with raid and lvm support
    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
  8. Edit grub.conf to point to new root /dev/vg0/lv0
  9. reboot

Convert /boot to raid1

Syndicate content
Comment