Sie sind auf Seite 1von 3

Playing with ZFS snapshots

January 10, 2011


Lingeswaran
Leave a comment
Go to comments
bash-3.00# zfs list /export/home
NAME USED AVAIL REFER MOUNTPOINT
rpool/export/home 6.57M 443M 6.57M /export/home
Here we are going to take an snpshot of /export/home
bash-3.00# zfs snapshot rpool/export/home@snap1
bash-3.00# zfs list
NAME USED AVAIL REFER MOUNTPOINT
rpool/export/home 10.1M 440M 10.1M /export/home
rpool/export/home@snap1 0 10.1M -
bash-3.00# cd /export/home
bash-3.00# mkfile 10m test2
bash-3.00# ls
TT_DB adminusr lingesh1 test1 test2
bash-3.00# cd
bash-3.00# zfs list
NAME USED AVAIL REFER MOUNTPOINT
rpool/export/home 20.1M 430M 20.1M /export/home
rpool/export/home@snap1 25K 10.1M -
We have changed or new data in our filesystem (After first snapshot, volume have
some addtional data here)
Now we will take second snapshot ..
bash-3.00# zfs snapshot rpool/export/home@snap2
bash-3.00# zfs list
NAME USED AVAIL REFER MOUNTPOINT
rpool/export/home 20.1M 430M 20.1M /export/home
rpool/export/home@snap1 25K 10.1M -
rpool/export/home@snap2 0 20.1M -
Let try to restore first snapshot!
bash-3.00# zfs rollback rpool/export/home@snap1
cannot rollback to rpool/export/home@snap1': more recent snapshots exist
use -r to force deletion of the following snapshots:
rpool/export/home@snap2
Oops.If you want to restore fist snapshot you need to remove the second one.then
only you can restore first one.(if you issue -r option if will remove latest sna
pshot of volume )
Lets try to restore second snap
bash-3.00# zfs rollback rpool/export/home@snap2
bash-3.00# zfs list
NAME USED AVAIL REFER MOUNTPOINT
rpool/export/home 20.1M 430M 20.1M /export/home
rpool/export/home@snap1 25K 10.1M -
rpool/export/home@snap2 0 20.1M -
yesit is restored..
Now will try to restore first snap after destroying second snap
bash-3.00# cd /export/home
bash-3.00# ls
TT_DB adminusr lingesh1 test1 test2
bash-3.00# zfs destroy rpool/export/home@snap2
bash-3.00# ls
TT_DB adminusr lingesh1 test1 test2
bash-3.00# zfs rollback rpool/export/home@snap1
bash-3.00# ls
TT_DB adminusr lingesh1 test1
Now you can see our volume has been overwritten by snapshot.Test2 file disappear
ZFS one of the the future zfs send option
We can send snapshot to remote location using zfs send optionhere we will assume
/test is nas location or any nfs location
bash-3.00# zfs send -R rpool/export/home@snap1 > /test/home@snap1
bash-3.00# cd /test
bash-3.00# ls -l
-rw-rr 1 root root 10864244 Jul 29 22:08 home@snap1
bash-3.00# zfs list
NAME USED AVAIL REFER MOUNTPOINT
rpool/export/home 10.1M 440M 10.1M /export/home
rpool/export/home@snap1 22K 10.1M -
Now we will destroy local snapshotnow we have snapshot backup avail in NAS or NFS
(here /test )
bash-3.00# zfs destroy rpool/export/home@snap1
bash-3.00# zfs list
NAME USED AVAIL REFER MOUNTPOINT
rpool/export/home 10.1M 440M 10.1M /export/home
rpool/swap 524M 440M 524M -
NASFILER:/vol1 2.21G 5.60G 2.21G /test
bash-3.00# zfs receive -d rpool < /test/home\@snap1
cannot receive new filesystem stream: destination rpool/export/home exists
must specify -F to overwrite it
We will bring that snapshot back to our machine
bash-3.00# zfs receive -dF rpool < /test/home\@snap1
bash-3.00# zfs listNAME USED AVAIL REFER MOUNTPOINT
rpool/export/home 10.1M 440M 10.1M /export/home
rpool/export/home@snap1 0 10.1M -
rpool/swap 524M 440M 524M -
test 2.21G 5.60G 2.21G /test
So using ZFS snapshot we can take backup of online filesystem easily(specially f
or rootpools).Better we can create script for zfs snapshot & put in cronjobs ,so
that daily or weekly or monthly basis snapshot will send to NAS or NFS location
.Whenever we need we can easily restore from NAS location.
Do you know scripting ?
here we go ..
#!/usr/bin/ksh
# Variables
DATE=`date +%Y%m%d`
DATASET=`df -k / | tail -1 | awk {print $1} | cut -d/ -f3`
HOSTNAME=`hostname`
NFS=/net/mum-nas01/unix/rpoolbackup/dmp1
# Recursive snapshot of rpool
zfs snapshot -r rpool@${DATE}
# Send the rpool dataset and the root filesystem dataset (variable name)
zfs send -v rpool@${DATE} > ${NFS}/${HOSTNAME}.rpool.${DATE}.zfsnsap
zfs send -Rv rpool/ROOT/${DATASET}@${DATE} > ${NFS}/${HOSTNAME}.${DATASET}.${DAT
E}.zfssnap
# Delete snapshot
zfs destroy -r rpool@${DATE}
# Exit successful
exit 0
i hope this will help..

Das könnte Ihnen auch gefallen