Fixed a typo in README.
[dm-merge.git] / README
blobf511def23668482f5f54ab276f6dbd689db89b0d
1 dm-merge
2 --------
4 dm-merge is a simple tool to apply changes recorded in a copy-on-write
5 exception table. It can be effectively used to either "commit" the changes into
6 the source (as made with simple snapshot target) or "rollback" (reverting to a
7 state the snapshot was created; as made with snapshot linked to snapshot-origin
8 target). And while LVM snapshots are simply (maybe not so simply, actually) the
9 latter case, it can revert a logical volume to the exact state it was when the
10 snapshot was taken.
12 dm-merge simply reads an exception table and applies the changes back to the
13 source
15 It can be thought of as a C port of Lars Ellenberg's 'list_exception_chunks'
16 perl script [1]. I liked the idea very much.
20 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
22 Disclaimer: be warned: the tool was only tested on X86 and X86_64 little endian
23 machines! It is still experimental. Use at _your_ _own_ risk! Before using it,
24 you should understand how device-mapper, LVM and snapshots work.
26 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
30 1. Usage
31 --------
33 dm-merge [options] -i <snapshot_device> [ -o <output_device> ]
35 Options:
36 -f              REALLY do it (no dry run)
37 -d              Print dd lines as list_exception_chunks.pl would
38 -D              Try to use O_DIRECT
39 -v              Be verbose (more '-v's increase verbosity)
40 -i <file>       Input (snapshot) COW (copy-on-write) filename
41 -o <file>       Output (the device being snapshoted) filename
45 2. Scenarios
46 ------------
48 2.1 Reverting (LVM) snapshot
49 ----------------------------
51 Suppose you have a logical volume ${lv} in a virtual group ${vg} and a snapshot
52 ${sn} of ${lv} made by something like:
54     lvcreate -L ${some_size} -n ${sn} ${vg}/${lv}
56 As long as ${sn} isn't full it will behave like ${lv} at the time the snapshot
57 was taken.
59 Now you make some changes to ${lv} and realize you'd like to revert to the
60 state of ${sn}. This is when dm-merge comes into play.
62 With dm-merge you have basically two options:
64 1) make the changes while ${lv} is "inactive" (recommended)
66 2) keep ${lv} "active" and attempt the changes (for the adventurous)
69 2.1.1 dm-merge and inactive ${lv}
70 ---------------------------------
73 1) Duplicate the tables of ${lv} and snapshot storage:
75     dmsetup ${vg}-${lv}-real | dmsetup create tmp_lv
76     dmsetup ${vg}-${sn}-cow | dmsetup create tmp_cow
78 2) Deactivate the LV (the mappings will disappear, that's why we duplicate the
79 tables):
81     lvchange -a n ${vg}/${lv}
83 3) Flush buffers (better safe than sorry):
85     blockdev --flushbufs /dev/mapper/{tmp_lv,tmp_cow}
87 4) Make sure nothing else touches the data (it should _not_ be mounted!):
89     ...
91 5) First (purely informative; non-destructive) dm-merge run. See if the numbers
92 look reasonable...
94     dm-merge -i /dev/mapper/tmp_cow -o /dev/mapper/tmp_lv -vd
96 6) If everything seems OK, do it:
98     dm-merge -i /dev/mapper/tmp_cow -o /dev/mapper/tmp_lv -f
100 7) Flush buffers (better safe than sorry):
102     blockdev --flushbufs /dev/mapper/{tmp_lv,tmp_cow}
104 8) Now it should be done. You may remove the temporary mapping then:
106     dmsetup remove tmp_lv
107     dmsetup remove tmp_cow
109 9) The original snapshot may not be necessary anymore (it will show the same
110 data as the ${lv} now), so you can remove it:
112     lvremove ${vg}/${sn}
114 10) Activate the LV again:
116     lvchange -a y ${vg}/${lv}
120 2.1.2 dm-merge and active ${lv}
121 -------------------------------
123 1) Make sure nothing else touches the data (it should _not_ be mounted!);
124 perhaps "dmsetup suspend" could help a little...:
126     ...
128 2) Flush buffers (better safe than sorry):
130     blockdev --flushbufs /dev/mapper/${vg}-${sn}* /dev/mapper/${vg}-${lv}*
132 3) First (purely informative; non-destructive) dm-merge run. See if the numbers
133 look reasonable...
135     dm-merge -i /dev/mapper/${vg}-${sn}-cow -o /dev/mapper/${vg}-${lv}-real -vd
137 4) If everything seems OK, do it:
139     dm-merge -i /dev/mapper/${vg}-${sn}-cow -o /dev/mapper/${vg}-${lv}-real -f
141 5) Flush buffers (better safe than sorry):
142     
143     blockdev --flushbufs /dev/mapper/${vg}-${sn}* /dev/mapper/${vg}-${lv}*
145 6) The original snapshot may not be necessary anymore (it will show the same
146 data as the LV now, so you can remove it):
148     lvremove ${vg}/${sn}
152 2.2 Applying a copy-on-write back to the source ("commit")
153 ----------------------------------------------------------
155 With device mapper and the "snapshot" target (dm-snapshot != LVM snapshot [2]),
156 you can simply create a mapping that "redirects" all writes to a different
157 device so the source stays intact. So when not changed, data is read from the
158 source device; when changed, it is read from a special device (exception
159 table).
161 So you have some data mapping ${data}, a COW storage ${cow_s} and a dm-snapshot
162 mapping ${sn} [3] created with something like:
164     echo "0 $(blockdev --getsize /path/to/${data}) snapshot /path/to/${data} /path/to/${cow_s} P 8" | dmsetup create ${sn}
166 Now all writes made to /dev/mapper/${sn} go to /path/to/${cow_s}.
168 Imagine you are testing a program inside ${sn}. After testing you'd like to
169 apply the changes made in ${sn} back into ${data}.
171 Here comes dm-merge.
173 1) Make sure nothing else touches the data (it should _not_ be mounted!) ...
175     ...
177 2) Flush buffers (better safe than sorry):
179     blockdev --flushbufs /path/to/${data} /path/to/${cow_s} /dev/mapper/${sn}
181 3) First (purely informative; non-destructive) dm-merge run. See if the numbers
182 look reasonable...
184     dm-merge -i /path/to/${cow_s} -o /path/to/${data} -vd
186 4) If everything seems OK, do it:
188     dm-merge -i /path/to/${cow_s} -o /path/to/${data} -f
190 5) Flush buffers (better safe than sorry):
192     blockdev --flushbufs /path/to/${data} /path/to/${cow_s} /dev/mapper/${sn}
197 -----
199 [1] http://article.gmane.org/gmane.linux.lvm.general/9899
201 [2] LVM snapshots need "snapshot" and "snapshot-origin" dm targets to
202 accomplish the goal.
204 [3] Neither ${data} nor ${cow_s} has to be a device-mapper device (for the
205 simplest case). But if you want to do some clever tricks (such as table
206 changing so ${sn} takes place of ${data}; as shown at
207 http://linuxgazette.net/114/kapil.html), you'd need them to be.