Tuesday Nov 25, 2008

ZFS send/recv

After my moments of stupidity documented below I decided I'd fix the problem. I've coded up a script that will use zfs send and recv to replicate my home directory. At the moment it's manual, but I'll look into hooking into an automatic system:

#!/bin/bash

USER=fifors
HOST=stormspike.sfbay.sun.com
FS="rpool/export/home"
RS="rpool/zion-home-backup"
MAX_SNAP=15
NOW=`date +%Y%m%d%H%M%S`
INIT=0

set -- `getopt i $\*`
if [ $? != 0 ]
then
echo ${USAGE}
exit 2
fi

for i in $\*
do
case $i in
-i) echo Initialising Snapshot backup;
INIT=1;
shift;
continue;;
esac
done

ALIVE=`ping ${HOST} 2>&1 | grep -c alive`

if [ ${ALIVE} ]
then
SNAPS=`zfs list -t snapshot |grep "${FS}@" | wc -l | tr -d " "`
echo Determine incremental
if [ "${INIT}" == "0" ]
then
ISNAP=`zfs list -t snapshot | grep rpool/export/home@ |tail -1 |cut -d " " -f 1`
fi

echo "Creating zfs snapshot ${FS}@${NOW} ..."
zfs snapshot ${FS}@${NOW} > /dev/null 2> /tmp/error.$$
if [ $? -ne 0 ]
then
echo "Failed ($?)!"
cat /tmp/error.$$
rm /tmp/error.$$
exit 1
else
echo "Successfully created snapshot: ${FS}@${NOW} !"
fi
rm /tmp/error.$$
if [ ${SNAPS} -ge ${MAX_SNAP} ]
then
LAST=`zfs list -t snapshot | grep "${FS}@" | head -1 | awk '{ print $1}'`
echo "Destroying last snapshot: ${LAST}..."
zfs destroy ${LAST} > /dev/null 2> /tmp/error.$$
if [ $? -ne 0 ]
then
echo "Failed ($?)!"
cat /tmp/error.$$
rm /tmp/error.$$
exit 1
else
echo "Successfully destroyed snapshot: ${LAST} !"
fi
rm /tmp/error.$$
fi

if [ "${INIT}" == "1" ]
then
echo "Initialising the zfs replication of ${FS}..."
zfs send ${FS}@${NOW} | ssh ${USER}@${HOST} pfexec /sbin/zfs recv ${RS}@${NOW}
else
echo "Initiate the zfs send of ${FS}@${NOW} to ${RS}@${NOW}..."
zfs send -i ${ISNAP} ${FS}@${NOW} | ssh ${USER}@${HOST} pfexec /sbin/zfs recv -F ${RS}@${NOW}
fi

if [ $? -ne 0 ]
then
echo "Failed ($?)!"
exit 1
else
echo "Successfully synced snapshot: ${FS}@${NOW} and ${RS}@${NOW} !"
fi
else
echo "Cannot connect to ${HOST}"
fi

It's pretty simple really, just relies on the underlying aspects of ZFS to make it all ok.

Grr.. it looks like html destroys the format... I'll fix that later.

Monday Nov 24, 2008

Phew! Not a total doofus!

Turns out a judicious import from a LiveCD does the right thing. I just needed to pass the correct device string (s0, not p2).

It may turn out to prove that I am stupid in many other ways, but at least in this case it was recoverable ;-).

Why am I so stupid?

I always tend to prefer stuff on the bleeding edge warts and all. So I was in Baltimore for PASIG during the week and I suggested to a few folks they should consider using Celeste and a basis for a data store, seems fine right? It worked out of the box for me on OpenSolaris, they had a few problems so I rebooted into Ubuntu to install and try it there. Again no problems.

So whilst in Ubuntu I decided to use zfs-fuse to pull in my mail filters for Thunderbird. Again should be simple enough. I'd had problems before with this causing problems to the underlying zpool, but I thought this would be fine since I just wanted read access. Big mistake.

Ok, so what happens? When I try to reboot the ZFS filesystem isn't recognised by GRUB. Ok that's fine, I've seen it before. Simple solution, boot with the LiveCD import the pool done, right? Nope, unfortunately no LiveCD and I'm also not patient (hence the title of this entry). So what do I do next? Try and fail to create a OpenSolaris Live USB keyring. Then I get the idea that I should update ZFS fuse and see if there is anything I can do.

hg update, scons, sudo scons install. Good to go. Then I notice the ZFS version on the pool is only 10 and ZFS fuse goes all the way to 14. Maybe that's the problem.. This is where the good fairy should have been crying "Don't do it, Don't do it". Unfortunately there was no one around to pry my fingers away from the keyboard and I upgraded the filesystem.

Now ZFS doesn't see the pool at all... Now that I'm back in the office I'll try to do some surgery with zdb, but I'm not hopeful..

About

Peter Buckingham

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today