-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathzfs-clone-snapshot.sh
executable file
·42 lines (32 loc) · 1.5 KB
/
zfs-clone-snapshot.sh
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
31
32
33
34
35
36
37
38
39
40
41
42
#!/bin/sh -xe
snapshot=$1
pool=$( zpool list -H -o name )
if [ -z "$snapshot" ]; then
#host_disk=`zfs list -H -o name -r lib15/backup | grep '/[0-9]*$' | iselect --all --name="Select host and disk"`
host_disk=`zfs list -H -r -o name $( ls -d /$pool/{cluster,oscar} | sed 's,/,,' ) | grep '/0$' | iselect --all --name="Select host and disk"`
echo "# reading snapshots for $host_disk"
snapshot=`zfs list -o name -r -t snapshot $host_disk | sort -r | iselect --all --name="Select snapshot date to diff"`
test -z "$snapshot" && echo "no snapshot selected, aborting" && exit 1
fi
test -z "$snapshot" && echo "Usage: $0 zfs-snapshot" && exit 1
sudo zfs list -H -t snapshot -o name $snapshot | while read snapshot ; do
echo "# clone $snapshot"
clone=$( echo $snapshot | sed -e 's,^.*/cluster/,,' -e 's,^.*/oscar/,,' -e 's,/\([0-9]*\)@,-\1-,' )
sudo zfs clone $snapshot $pool/clone/$clone || true
# prefix hostname with CLONE-
#echo CLONE-$clone.local > /$pool/clone/$clone/etc/hostname
#echo 127.0.0.3 CLONE-$clone.local >> /$pool/clone/$clone/etc/hosts
i_sh=/$pool/clone/$clone/i.sh
cat <<__SHELL__ > $i_sh
#!/bin/sh -xe
apt remove -y acpid
__SHELL__
chmod 755 $i_sh
cp -rpv /srv/zfs-tools/clone-instance/* /$pool/clone/$clone/
cd /$pool/clone/$clone/
# modify shell prompt to include CLONE
echo 'PS1="CLONE $PS1"' >> root/.bashrc
echo 'PS1="CLONE $PS1"' >> home/dpavlin/.bashrc
systemd-nspawn --directory /$pool/clone/$clone /i.sh
echo "## cd /$pool/clone/$clone ; /srv/zfs-tools/ganeti-nspawn.sh --boot"
done