Never been to TextSnippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world (or not, you can keep them private!)

zfs migration script (See related posts)

First rev, works but could use improvement

#!/bin/bash
if [ $# -ne 2 ]
then
    echo "Usage: $0 host_to_send_to zpool_name_on_destination"
    exit
fi
SERVER=$1
ZPOOL=$2
echo
echo "*********************************************************************************"
echo "*                                                                               *"
echo "* Please note, this wrapper only creates migration scripts for filesystems with *"
echo "* existing snapshots. If you want to migrate a snapshot-less filesystem, just   *"
echo "* run 'zfs snapshot zpool/filesystem@migrate' to create a snapshot which will   *"
echo "* allow this script to transfer it to the destination zpool.                    *"
echo "*                                                                               *"
echo "*********************************************************************************"
echo
if [ -f ./tmp/${SERVER}.screens ]
then
echo
echo "******************************************************************************"
echo "*"
echo "* Sorry, tmp/${SERVER}.screens exists, please run 'rm tmp/*' and try again..."
echo "*"
echo "******************************************************************************"
echo
exit
else
if [ ! -d tmp ]
then
mkdir tmp
fi
fi
for z in `zfs list | grep @ | awk '{print $1}' `;
do
FSNAME=`echo $z | awk -F@ '{print $1}' | awk -F/ '{print $NF}'`
if [ -f tmp/${FSNAME}.migrate ] 
then
echo "zfs backup -i $PREV $z | ssh root@$SERVER zfs restore $ZPOOL/${FSNAME}" >> tmp/${FSNAME}.migrate
PREV=$z
else
echo "Processing snapshots for ${FSNAME}."
echo "zfs backup $z | ssh root@$SERVER zfs restore $ZPOOL/${FSNAME}" > tmp/${FSNAME}.migrate
echo "screen -m -d bash tmp/${FSNAME}.migrate" >> tmp/${SERVER}.screens
PREV=$z
fi
done
echo
echo "**************************************************************************"
echo "*"
echo "* Ok, all finished - You can either run them individually, or simply type"
echo "*"
echo "* bash tmp/${SERVER}.screens"
echo "*"
echo "* at a prompt to run them concurrently in disconnected screen sessions."
echo "*"
echo "**************************************************************************"
echo

You need to create an account or log in to post comments to this site.


Related Posts