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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
SquashFu - an alternative backup solution
Inspired by http://forums.gentoo.org/viewtopic-p-4732709.html
Requirements: aufs, aufs2-util, squashfs-tools, rsync
Goal: To create a backup solution which provides incremental backups and compression,
and which also provides an easy way to roll back.
Design:
A directory structure is created as follows:
backup_root/
|- seed.sfs
|- ro/
|- rw/
|- bins/
|-1/ <-- Monday incremental
|-2/ <-- Tuesday incremental
|-3/ <-- Wednesday incremental
|-4/ <-- Thursday incremental
|-5/ <-- Friday incremental
|-6/ <-- Saturday incremental
|-7/ <-- Sunday incremental
seed.sfs is created from an initial backup and compressed using SquashFS, which i
is simply a filesystem which focuses on compression, but is read only. It's mounted,
using a loopback device, on ro/. Using aufs2, a union mount is formed by ro/ and each
of the numbered bins, each corresponding to a day.
Wait, wat? What the heck IS a union mount? In simple terms, a union combines multiple
directories (which themselves could also be mount points) into a single resultant
mount point. Using our directory structure above as an example, each day (bin) is
overlayed (in order, its important) on the base (seed.sfs) to create what appears
to be an up to date backup in rw/. Skip the rest if you've had enough.
At the time of the backup, the day is determined in order to prepare the union. If
today is Thursday, `date +%u` returns 4. In order for rsync to properly create our
incremental, we need to compare current data with the seed plus incrementals leading
up to Thursday, so we create our Aufs mount with the branches bins/4, bins/3, bins/2,
bins/1, and ro/ (in that order). When rsync now writes to the resulting union, aufs
happily receives the data into the first available (writable) branch of the union,
which is bins/4. The next day, the union mount is reformed adding the next bin...
If and when you want to roll back, the process is simple. Mount the seed plus
the necessary bins to increment the seed up to the day of interest.
Warnings:
It is imperative that you do NOT touch the individual branches. You can and will
cause irrepairable damage to the union, rendering your incrementals worthless.
Further reading:
http://en.wikipedia.org/wiki/Aufs
http://en.wikipedia.org/wiki/UnionFS
http://aufs.sourceforge.net/
http://en.wikipedia.org/wiki/SquashFS
http://en.wikipedia.org/wiki/Rsync
|