lvm-ext4-snapshot/install.sh

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