Gentoo Archives: gentoo-user

From: Alex Schuster <wonko@×××××××××.org>
To: gentoo-user@l.g.o
Subject: snackup (was: Re: [gentoo-user] backup to a cold-swap drive)
Date: Fri, 07 May 2010 18:24:41
Message-Id: 201005072023.54772.wonko@wonkology.org
In Reply to: Re: [gentoo-user] backup to a cold-swap drive by Iain Buchanan
1 Iain Buchanan writes:
2
3 > On Thu, 2010-04-29 at 16:44 +0200, Alex Schuster wrote:
4
5 > > using this script, adapted to their needs, I started to rewrite it in
6 > > a way that it reads a config file, and no modification of the script
7 > > itself is necessary. If anyone is interested, send me an email.
8 >
9 > interested! So is it on sourceforge yet ;)
10
11 Sorry, it took a little longer. I was ill, and then these scripts tend to
12 grow and grow until I am satisfied with them. It's still not perfect, but
13 I think at the moment it does what it should do.
14
15 Still not on sourceforge, but here: http://www.wonkology.org/utils/snackup
16 The name is silly, but I kinda like it now. A backup utilizing LVM
17 snapshots... snapshot backup... snackup!
18
19 It needs a config file that is looked up in some default locations, or can
20 be specified with the -c option. Use option -T to generate a template that
21 has information on the syntax and some examples. In short:
22
23 The config file defines targets you give as arguments to snackup. So
24 'snackup home' backs up your /home partition, 'snackup etc' creates a .tgz
25 file of your /etc. The config file is sourced, so you can put any bash
26 stuff you want into there, like some shell functions you want to have
27 executed. For example, I want my /var/log/portage/*.log files to be
28 compressed before I backup my /var partition.
29
30 A target is started by a colon, followed by name, type, source and
31 destination (and optionally more), separated by one or more tab
32 characters. Type can be 'cp', 'dd', 'tar', 'rsync' or 'rdiff'. I only
33 tested dd, tar and rdiff so far, though. The source directory may be
34 prefixed by the volume group and LVM of that partition in order to create
35 an lvm snapshot first. You may add a LUKS key if the partition is
36 encrypted. The source may contain wildcards. In that case, all matching
37 files are backed up to the destination. If the type has a * appended, all
38 matching files are backed up individually. Some examples:
39
40 : tar kde .kde* /backup/kde.%s
41
42 Target 'kde' will backup all your .kde* directories to /backup/kde.tar
43 (the %s is replaced by a suffix, usually tar). You need to be in your home
44 directory, otherwise the path will not be found. This is not necessary if
45 you use ~//.kde* instead.
46
47 : kernels tar* /usr/src//linux-* /backup/src/%f.%s -j - lsf
48
49 Target 'kernels' will backup your /usr/src/linux-* directories
50 individually - one tar file for each (note the * appendended to the tar
51 target type). The -z option will be passed to the tar command, and the
52 suffix is changed to tgz accordingly.
53 The // denotes that the backup should be done locally from the directory
54 left to the //. Otherwise, the full path would be included in the tar
55 file.
56
57 : tar etc /etc /backup/etc_%d.%s -j
58
59 Target 'etc' will tar your /etc directory, compressed with bzip2. The %d
60 will be replaced by the current date. You can change the date format by
61 re-defining a date() shell function.
62 You will get a message about tar removing the leading /, you can avoid it
63 by replacing /etc by ///etc, meaning that your local directroy will be /.
64
65 : boot dd /dev/sda5 /dev/sdb5 bs=32M
66
67 Target 'boot' will backup a boot partition with dd. Options like the
68 bs=32M are added directly to the dd command.
69
70 : home rsync system/home::. /backup/home/
71
72 Target 'home' will create a LVM snapshot of the /dev/system/home logical
73 volume, mount it and back it up with rdiff-backup. The '.' could also be a
74 / or left off.
75
76 : var rsync system/var::/ /backup/var/ - ziplog
77
78 Similar, but the command ziplog will be executed before the backup,
79 compressing some log files. It must be defined in the config file.
80
81 The script has some options:
82
83 -c file location of config file
84 -C clear destination first
85 -d dummy mode, just show what would be done
86 -f force backup (the initial rdiff-backup may need this)
87 -h show this help
88 -l output to log file, too
89 -L log file (default:/home/wonko/log/snackup.log); may be a
90 directory (add a trailing slash) to create target-specific logs
91 -n l use nice level l (default:10, 0 to turn off)
92 -N l use ionice level l (default:3, 0 to turn off)
93 -o extra options that will added to the actual backup command
94 -s size size of LVM snapshot (default:2G)
95 -S char replace tab as delimiter for targets in config file
96 -T output config file template
97 -v verbose output; may be given multiple times
98 1: some extra output; 2: add -v to commands; 3: set -xv
99 -V output version information and exit
100
101 Most important are:
102 -c to specify the location of the config file
103 -d to output what would be done, you will see the final tar / rdiff-
104 backup / whatever command with all its options.
105 -T to see a template. Save it with snackup -T > ~/.snackup and then
106 modify your ~/.snackup file.
107 -o to add whichever options you like to the final command. These (and -j
108 and -z) override options already defined in the config file.
109
110 Too complicated? Overkill? Maybe. But I like it, and now I do not have to
111 write another script for every system I want to backup. And I like the LVm
112 snapshotting to be done automatically. It's not that hard, but it's
113 annoying to do it by hand, even more as all my volumes are encrypted.
114
115 These are my own targets:
116
117 : boot dd /dev/boot /dev/sdb5 - - -
118 : backup rdiff weird/backup::/etc/key::. /backup/weird/backup - - -
119 : local rdiff weird/local::/etc/key::. /backup/weird/local - - -
120 : home rdiff weird/home::/etc/key::. /backup/weird/home - - -
121 : med rdiff weird/med::/etc/key::. /backup/weird/med - - -
122 : mp3 rdiff weird/mp3::/etc/key::. /backup/weird/mp3 - - -
123 : mpeg rdiff weird/mpeg::/etc/key::. /backup/weird/mpeg - - -
124 : opt rdiff weird/opt::/etc/key::. /backup/weird/opt - - -
125 : root rdiff weird/root::/etc/key::. /backup/weird/root - - -
126 : usr rdiff weird/usr::/etc/key::. /backup/weird/usr - - -
127 : var rdiff weird/var::/etc/key::. /backup/weird/var - zipLog -
128 : etc tar ///etc /backup/conf/etc/etc_%d.%s -z - lsf
129 : kernels tar* /usr/src//linux-* /backup/weird/src/%f.%s -j - lsf
130 : portage rsync /var/portage/packages /backup/weird/portage - - -
131 : kde tar ~//.kde* /backup/wonko/home/kde-%d.%s -z - lsf
132 : dot tar ~//.??* /backup/extern/dot-%d.%s -z - lsf
133
134
135 At last, the disclaimer: Use it at your own risk! This is a script of some
136 800 lines of bash code some guy wrote, it messes around with LVM stuff,
137 creates and removes temporary directories and even has an option to wipe
138 the destination completely. I'm quite confident that no harm will be done,
139 and I do not suggest you to take a backup before daring to try this script,
140 but anyway.
141
142 Use the -d option first to test what actually would be going on, before you
143 do a real backup!
144
145 Hope this is of good use to someone. For me it is, I will be using it on
146 several systems, and now I only have to make little changes in the config
147 file for each system, but not at the script.
148
149 Suggestions and bug reports are welcome of course.
150
151 Wonko

Replies

Subject Author
Re: snackup (was: Re: [gentoo-user] backup to a cold-swap drive) covici@××××××××××.com
[gentoo-user] Re: snackup Alex Schuster <wonko@×××××××××.org>