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