Something like that:
/bin/sh
mkdir /var/jails && cd /var/jails
for D in `ls`; do
mkdir -p $D/root $D/bin $D/dev $D/etc $D/lib $D/libexec $D/tmp $D/usr $D/var $D/home/$D
chmod o+rwxt $D/tmp
mtree -deU -f /etc/mtree/BSD.var.dist -p $D/var
done
cd /usr/src
for D in `ls /var/jails/`; do
make distribution DESTDIR=/var/jails/$D
done
cat >> /etc/rc.conf
# Jails
jail_enable="YES"
jail_mount_enable="YES"
jail_sysvipc_allow="YES"
jail_list="jail1 jail2 jail3"
## jail1
jail_jail1_name="jail1"
jail_jail1_hostname="jail1.com"
jail_jail1_ip="127.0.0.10/8"
jail_jail1_interface="lo0"
jail_jail1_rootdir="/var/jails/jail1"
jail_jail1_devfs_enable="YES"
jail_jail1_devfs_ruleset="devfsrules_jail"
## jail2
jail_jail2_name="jail2"
jail_jail2_hostname="jail2.com"
jail_jail2_ip="127.0.0.20/8"
jail_jail2_interface="lo0"
jail_jail2_rootdir="/var/jails/jail2"
jail_jail2_devfs_enable="YES"
jail_jail2_devfs_ruleset="devfsrules_jail"
## jail3
jail_jail3_name="jail3"
jail_jail3_hostname="jail3.com"
jail_jail3_ip="127.0.0.30/8"
jail_jail3_interface="lo0"
jail_jail3_rootdir="/var/jails/jail3"
jail_jail3_devfs_enable="YES"
jail_jail3_devfs_ruleset="devfsrules_jail"
^D
cat /etc/fstab.jail1
/var/jails/ruby/bin /var/jails/jail1/bin nullfs ro 0 0
/var/jails/ruby/lib /var/jails/jail1/lib nullfs ro 0 0
/var/jails/ruby/libexec /var/jails/jail1/libexec nullfs ro 0 0
/var/jails/ruby/usr /var/jails/jail1/usr nullfs ro 0 0
tmpfs /var/jails/jail1/tmp tmpfs rw,size=1G 0 0
Tuesday, December 28, 2010
Sunday, November 7, 2010
Simple script to monitor replication in PostgreSQL 9
Here is the simple script to monitor PostgreSQL replication on FreeBSD:
========= Cut here =========
#!/bin/sh
# Timeout in seconds
readonly timeout=600
last_chkp=`pg_controldata /var/db/pgsql/ | grep "Time of latest checkpoint" | sed "s/.*checkpoint: *//"`
last_chkp=`date -j -f "%a %b %d %T %Z %Y" "$last_chkp" "+%s"`
now=`date`
now=`date -j -f "%a %b %d %T %Z %Y" "$now" "+%s"`
if [ `expr $now - $last_chkp` -gt $timeout ]; then
echo Replication kaput!
fi
========= Cut here =========
#!/bin/sh
# Timeout in seconds
readonly timeout=600
last_chkp=`pg_controldata /var/db/pgsql/ | grep "Time of latest checkpoint" | sed "s/.*checkpoint: *//"`
last_chkp=`date -j -f "%a %b %d %T %Z %Y" "$last_chkp" "+%s"`
now=`date`
now=`date -j -f "%a %b %d %T %Z %Y" "$now" "+%s"`
if [ `expr $now - $last_chkp` -gt $timeout ]; then
echo Replication kaput!
fi
Monday, October 4, 2010
Tarsnap cleanup on FreeBSD
The simple script to preform tarsnap cleanup on FreeBSD:
#!/bin/sh
keyfile="/path/to/rw_keyfile"
# man(1) date will help (keep files for last 7 days in this example)
# we prefer to keep files in this format 2009-10-18+06:15-database as mentioned in earlier post
rd=`date -v-7d -v0H -v0M -v0S`
pd=`date -j -f "%a %b %d %T %Z %Y" "$rd" "+%s"`
for file in `tarsnap --keyfile $keyfile --list-archives | sort`; do
fd=`echo -n $file | cut -d'+' -f 1`
fd=`date -j -f "%Y-%m-%d %T" "$fd 00:00:00" "+%s"`
if [ $fd -lt $pd ]; then
echo Deleting the $file archive
tarsnap --keyfile $keyfile -d -f $file
fi
done
#!/bin/sh
keyfile="/path/to/rw_keyfile"
# man(1) date will help (keep files for last 7 days in this example)
# we prefer to keep files in this format 2009-10-18+06:15-database as mentioned in earlier post
rd=`date -v-7d -v0H -v0M -v0S`
pd=`date -j -f "%a %b %d %T %Z %Y" "$rd" "+%s"`
for file in `tarsnap --keyfile $keyfile --list-archives | sort`; do
fd=`echo -n $file | cut -d'+' -f 1`
fd=`date -j -f "%Y-%m-%d %T" "$fd 00:00:00" "+%s"`
if [ $fd -lt $pd ]; then
echo Deleting the $file archive
tarsnap --keyfile $keyfile -d -f $file
fi
done
Script to perform tarsnapping of data on FreeBSD
Here is the script to perform tarsnapping on FreeBSD:
#!/bin/sh
# Directories to backup
DIRS=/usr/local/etc/tarsnap-backup.conf
#EXTRA_FLAGS=--dry-run
BACKUP=`date "+%Y-%m-%d+%H:%M"`
TARSNAP="/usr/local/bin/tarsnap"
# Do backups
IFS='
'
for dirs in `grep -v -e '^#.' $DIRS`; do
# Needs to set IFS to space to allow passing arguments to tarsnap
IFS=' '
echo ${dirs}
$TARSNAP $EXTRA_FLAGS -c -f $BACKUP-${dirs}
done
The conf file should look like:
archive_name1 /list /of /directories1
archive_name2 /list /of /directories2
misc /root /etc /boot/loader.conf /usr/local/etc /usr/local/opt /var/cron/tabs /var/services /var/mail /var/qmail/control /var/qmail/alias
#!/bin/sh
# Directories to backup
DIRS=/usr/local/etc/tarsnap-backup.conf
#EXTRA_FLAGS=--dry-run
BACKUP=`date "+%Y-%m-%d+%H:%M"`
TARSNAP="/usr/local/bin/tarsnap"
# Do backups
IFS='
'
for dirs in `grep -v -e '^#.' $DIRS`; do
# Needs to set IFS to space to allow passing arguments to tarsnap
IFS=' '
echo ${dirs}
$TARSNAP $EXTRA_FLAGS -c -f $BACKUP-${dirs}
done
The conf file should look like:
archive_name1 /list /of /directories1
archive_name2 /list /of /directories2
misc /root /etc /boot/loader.conf /usr/local/etc /usr/local/opt /var/cron/tabs /var/services /var/mail /var/qmail/control /var/qmail/alias
Subscribe to:
Posts (Atom)