lvm-ext4-snapshot/install.sh

raw link view readme
1 create ()
2 {
3 parted -s /dev/sd$1 mklabel gpt
4 parted -s /dev/sd$1 mkpart primary 1MiB 100%
5 parted -s /dev/sd$1 set 1 lvm on
6 }
7
8 create b
9 create c
10 create d
11 create e
12
13 partprobe
14
15 pvcreate /dev/sd[b-e]1
16
17 vgcreate vg_core /dev/sd[b-e]1
18
19 lvcreate -l 50%FREE vg_core -n lv_sandbox
20
21 mkfs.ext4 /dev/vg_core/lv_sandbox
22
23 mkdir /var/sandbox
24
25 echo "`blkid | grep lv_sandbox | awk '{ print $2 }'` /var/sandbox ext4 defaults 0 0" >> /etc/fstab
26
27 mount -a
28
29 sed -i.original "/^[ \t]*#/d;/^$/d;s/snapshot_autoextend_threshold = 100/snapshot_autoextend_threshold = 75/" /etc/lvm/lvm.conf
30
31 # dd if=/dev/zero of=/var/sandbox/file-before.img bs=1M count=10
32
33 echo original content > /var/sandbox/file.txt
34
35 lvcreate --snapshot --size=10G --name=snap01 /dev/vg_core/lv_sandbox
36
37 # for n in `seq 100`; do dd if=/dev/zero of=/var/sandbox/$n-file-after.img bs=1M count=10; done
38
39 echo additional content >> /var/sandbox/file.txt
40
41 mkdir /var/sandbox-snap
42
43 cat > /root/mount-snapshot.sh << EOF
44 mount -o rw /dev/mapper/vg_core-snap01 /var/sandbox-snap
45 echo COMPARE /var/sandbox-snap and /var/sandbox
46 EOF
47 chmod +x /root/mount-snapshot.sh
48
49 cat > /root/restore-snapshot.sh << EOF
50 cd
51 umount /var/sandbox /var/sandbox-snap
52 lvconvert --merge /dev/mapper/vg_core-snap01
53 mount /var/sandbox
54 echo EXAMINE /var/sandbox
55 EOF
56 chmod +x /root/restore-snapshot.sh
57
58 cat > /root/merge-snapshot-into-main.sh << EOF
59 echo replaced content >> /var/sandbox-snap/file.txt
60 cd
61 umount /var/sandbox /var/sandbox-snap
62 lvconvert --merge /dev/mapper/vg_core-snap01
63 mount /var/sandbox
64 echo EXAMINE /var/sandbox
65 EOF
66 chmod +x /root/merge-snapshot-into-main.sh
67
68 cat > /root/remove-snapshot.sh << EOF
69 cd
70 umount /var/sandbox-snap
71 lvremove /dev/vg_core/snap01 -y
72 EOF
73 chmod +x /root/remove-snapshot.sh
74