File: mylvmbackup.1

package info (click to toggle)
mylvmbackup 0.9-1
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 192 kB
  • ctags: 62
  • sloc: perl: 1,142; makefile: 121; sh: 121
file content (425 lines) | stat: -rw-r--r-- 15,891 bytes parent folder | download
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
.\"     Title: mylvmbackup
.\"    Author: 
.\" Generator: DocBook XSL Stylesheets v1.73.2 <http://docbook.sf.net/>
.\"      Date: 07/10/2008
.\"    Manual: 
.\"    Source: 
.\"
.TH "MYLVMBACKUP" "1" "07/10/2008" "" ""
.\" disable hyphenation
.nh
.\" disable justification (adjust text to left margin only)
.ad l
.SH "NAME"
mylvmbackup - a utility for creating MySQL backups using LVM snapshots
.SH "SYNOPSIS"
\fImylvmbackup\fR [OPTIONS]
.sp
.SH "DESCRIPTION"
mylvmbackup is a tool for quickly creating backups of MySQL server\'s data files\. To perform a backup, mylvmbackup obtains a read lock on all tables and flushes all server caches to disk, makes an LVM snapshot of the volume containing the MySQL data directory, and unlocks the tables again\. The snapshot process takes only a small amount of time\. When it is done, the server can continue normal operations, while the actual file backup proceeds\.
.sp
The LVM snapshot is mounted to a temporary directory and all data is backed up using the \fItar\fR program\. By default, the archive file is created using a name of the form \fIbackup\-YYYYMMDD_hhmmss_mysql\.tar\.gz\fR, where \fIYYYY\fR, \fIMM\fR, \fIDD\fR, \fIhh\fR, \fImm\fR, and \fIss\fR represent the year, month, day, hour, minute, and second of the time at which the backup occurred\. The prefix \fIbackup\fR, date format and file suffix may be modified\. The use of timestamped archive names allows you to run mylvmbackup many times without danger of overwriting old archives\.
.sp
Alternatively, instead of \fItar\fR, you may use \fIrsync\fR\. This process is nearly identical, with the exception that the file suffix is not used\. Currently, the rsync backup is primarily developed for performing local backups\. You can configure it for backing up to a remote rsync server, but this is not fully tested in all possible configurations yet and may change at some point\.
.sp
.SH "GENERAL HINTS"
It is required to run mylvmbackup on the same host where the MySQL server runs\. If your MySQL daemon is not listening on localhost or using the default socket location, you must specify \fI\-\-host\fR or \fI\-\-socket\fR\. Even though mylvmbackup communicates with the server through a normal client connection to obtain the read lock and flush data, it performs the actual backup by accessing the file system directly\. It is also a requirement that the MySQL server\'s data directory resides on an LVM volume\. (It is, however, a good idea to do the LVM backup to a different partition than the one where the data directory resides\. Otherwise, there is a good chance that LVM will run out of undo space for LVM snapshot maintenance and the backup will fail\.)
.sp
The user who invokes mylvmbackup must have sufficient filesystem permissions to create the LVM snapshot and mount it\. This includes read/write access to the backup directory\.
.sp
If you plan to back up InnoDB tables using LVM snapshots, be advised that it is not sufficient to lock the tables and issue the \fIFLUSH TABLES\fR command to get the table files into a consistent state\. When starting the MySQL server from these restored files, InnoDB will detect these tables as being in an inconsistent state and will perform a recovery run before the tables can be accessed again\. As this can potentially take some time (which you may not want to spend after restoring a server and trying to get it back on its feet as fast as possible), consider using the option \fI\-\-innodb_recover\fR, which will perform the recovery operation on the backup snapshot prior to archiving it\.
.sp
The recovery operation is performed by spawning a second mysqld instance that uses the snapshot volume as the data directory\. Note that this functionality currently assumes the default InnoDB configuration \- it does not work properly if you use options like \fI\-\-innodb\-file\-per\-table\fR, \fI\-\-innodb\-data\-home\-dir\fR, \fI\-\-innodb\-data\-file\-path\fR or \fI\-\-innodb\-log\-group\-home\-dir\fR that modify the default file layout for InnoDB tables\.
.sp
Also note that this only works when using writable LVM snapshots and thus requires LVM2 (the script performs a test for this and will disable log recovery in the case it finds an LVM1 system)\. This will prolong the time needed to perform the actual backup, but will save you precious time when you eventually have to restore from this backup set\.
.sp
If you use InnoDB tables exclusively, you may also want to consider to include the option \fI\-\-skip_flush_tables\fR, to avoid the probably time\-consuming and in this case unnecessary flushing of buffers\. But don\'t enable this option when MyISAM tables are involved!
.sp
.SH "HOOKS"
It is possible to run arbitrary external programs or scripts (hooks) at various stages of the backup process, to perform additional actions as part of the backup process\.
.sp
These scripts or symbolic links to executables should be placed in the directory that the \fIhooksdir\fR configuration option points to (\fI/usr/share/mylvmbackup\fR by default)\. They should return zero upon successful completion, any non\-zero return value will be considered a failure which will be logged\.
.sp
The names of the scripts or symbolic links reflect the stage in which the hook will be called\. Currently, the following stages exist:
.sp
.sp
.RS 4
\h'-04'\(bu\h'+03'
\fIpreconnect\fR: before a connection to the database server is established
.RE
.sp
.RS 4
\h'-04'\(bu\h'+03'
\fIpreflush\fR: before calling FLUSH TABLES
.RE
.sp
.RS 4
\h'-04'\(bu\h'+03'
\fIpresnapshot\fR: before the file system snapshot is created
.RE
.sp
.RS 4
\h'-04'\(bu\h'+03'
\fIpreunlock\fR: before the database tables are unlocked again
.RE
.sp
.RS 4
\h'-04'\(bu\h'+03'
\fIpredisconnect\fR: before the connection to the database server is released
.RE
.sp
.RS 4
\h'-04'\(bu\h'+03'
\fIpremount\fR: before the snapshot volume is mounted
.RE
.sp
.RS 4
\h'-04'\(bu\h'+03'
\fIprebackup\fR: before the snapshot backup will be performed
.RE
.sp
.RS 4
\h'-04'\(bu\h'+03'
\fIprecleanup\fR: before the snapshot is unmounted and discarded
.RE
These hooks are optional and will only be called if a file for the particular stage exists and is executable\. The execution of all hooks can be supressed by passing the \fI\-\-skip_hooks\fR option or by setting the \fIskip_hooks\fR configuration option to \fI1\fR;
.sp
.SH "OPTIONS"
mylvmbackup supports the following command line options\. The same options can also be defined in the \fI/etc/mylvmbackup\.conf\fR configuration file (omitting the leading dashes, of course)\.
.PP
\-\-user=string
.RS 4
Specifies the username to use for connecting to the MySQL server\. The default is
\fIroot\fR\.
.RE
.PP
\-\-password=string
.RS 4
Specifies the password to use for connecting to the MySQL server\. The default is the empty string (no password)\.
.RE
.PP
\-\-host=string
.RS 4
Specifies the host name to use for connecting to the MySQL server\. The default is the empty string\.
.RE
.PP
\-\-port=number
.RS 4
Specifies the TCP port number to use for connecting to the MySQL server\. The default is
\fI3306\fR\.
.RE
.PP
\-\-socket=string
.RS 4
Specifies the path to the local socket file, if it is not located at the default location\. The default is the empty string\.
.RE
.PP
\-\-innodb_recover
.RS 4
Run InnoDB recovery on the writable snapshot (LVM2 only) prior to performing the backup\.
.RE
.PP
\-\-skip_flush_tables
.RS 4
Don\'t issue a
\fIFLUSH TABLES WITH READ LOCK\fR
command before creating the snapshot\. Only use this option when backing up InnoDB tables (as they don\'t support this function anyway and will require recovery in any case)\. This option skips the (probably time consuming) flushing of buffers\.
.RE
.PP
\-\-extra_flush_tables
.RS 4
If your database performs a lot of writes, it may help to perform an extra initial
\fIFLUSH TABLES\fR
so that the
\fIlvcreate\fR
can finish within the interactivity timeout during the read\-locked flush\.
.RE
.PP
\-\-pidfile=string
.RS 4
Specifies the full path and file name to the PID file of the server instance that is spawned to perform the InnoDB recovery (see option
\fI\-\-innodb_recover\fR)\. Must be different from the PID file that the actual running server uses\. The default is
\fI/var/tmp/mylvmbackup_recoverserver\.pid\fR
.RE
.PP
\-\-lvcreate=string
.RS 4
Specifies the pathname for the
\fIlvcreate\fR
program\. The default is
\fIlvcreate\fR\.
.RE
.PP
\-\-lvremove=string
.RS 4
Specifies the pathname for the
\fIlvremove\fR
program\. The default is
\fIlvremove\fR\.
.RE
.PP
\-\-lvs=string
.RS 4
Specifies the pathname for the
\fIlvs\fR
program\. The default is
\fIlvs\fR\.
.RE
.PP
\-\-mysqld_safe=string
.RS 4
Specifies the pathname for the
\fImysqld_safe\fR
program\. The default is
\fImysqld_safe\fR\. Only used to perform InnoDB recovery\.
.RE
.PP
\-\-mycnf=string
.RS 4
Specifies the name of the MySQL config file to include in the backup\. The default is
\fI/etc/my\.cnf\fR\.
.RE
.PP
\-\-skip_mycnf
.RS 4
Skip backing up the MySQL configuration file\. The default is to include a copy of the configuration file in the backup\.
.RE
.PP
\-\-hooksdir=string
.RS 4
The location of external scripts or executable to be called during various stages of the backup\. See the HOOKS section in this manual page for more info\. The default is
\fI/usr/share/mylvmbackup\fR\.
.RE
.PP
\-\-skip_hooks
.RS 4
Skip invoking any external hooks during the backup\.
.RE
.PP
\-\-vgname=string
.RS 4
Specifies the volume group of the logical volume where the MySQL data directory is located\. The default is
\fImysql\fR\.
.RE
.PP
\-\-lvname=string
.RS 4
Specifies the name of the logical volume where the MySQL data directory is located\. The default is
\fIdata\fR\.
.RE
.PP
\-\-backuplv=string
.RS 4
Specifies the name of the logical volume for the snapshot volume\. The default is appending "_snapshot" to the lvname\.
.RE
.PP
\-\-relpath=string
.RS 4
Relative path on the logical volume to the MySQL data directory\. The default is the empty string\.
.RE
.PP
\-\-lvsize=string
.RS 4
Specifies the size for the snapshot volume\. The default is
\fI5G\fR
(5 gigabytes)\.
.RE
.PP
\-\-backuptype=string
.RS 4
Specifies what type of backup to perform\. The available options are
\fItar\fR
and
\fIrsync\fR\.
.RE
.PP
\-\-prefix=string
.RS 4
Prefix added to the backup file names\. It is also appended to the name of the directory used to mount the snapshot volume\. The default value is
\fIbackup\fR\.
.RE
.PP
\-\-datefmt=string
.RS 4
Format of the time stamp included in the backup file name\. See the
\fIDate::Format\fR
perldoc page for a description of the format\. The default value is
\fI%Y%m%d_%H%M%S\fR, which creates a time stamp like
\fIYYYYMMDD_HHMMSS\fR, e\.g\.
\fI20070531_112549\fR
.RE
.PP
\-\-mountdir=string
.RS 4
Path for mounting the snapshot volume to\. The default value is
\fI/var/tmp/mylvmbackup/mnt/\fR\.
.RE
.PP
\-\-backupdir=string
.RS 4
Specifies the pathname of the directory where the archive files will be written to\. The backup directory must not be on the same volume as the MySQL data directory\. Instead of a local directory, you can also provide a valid rsync URL here, e\.g\.
\fIhostname::rsync\-module/path\fR\. This requires a properly configured remote rsync setup (e\.g\. pre\-setup SSH keys and a valid rsyncd\.conf file)\. Note that using rsync for remote backups is still under development and the way to configure it may change! The default is
\fI/var/tmp/mylvmbackup/backup/\fR
.RE
.PP
\-\-mount=string
.RS 4
Specifies the pathname for the
\fImount\fR
program\. The default is
\fImount\fR\.
.RE
.PP
\-\-umount=string
.RS 4
Specifies the pathname for the
\fIumount\fR
program\. The default is
\fIumount\fR\.
.RE
.PP
\-\-tar=string
.RS 4
Specifies the pathname for the
\fItar\fR
program\. The default is
\fItar\fR\.
.RE
.PP
\-\-tararg=string
.RS 4
Specifies the initial arguments for the
\fItar\fR
program\. The default is
\fIcvzf\fR\.
.RE
.PP
\-\-tarsuffixarg=string
.RS 4
Specifies the suffix arguments for the
\fItar\fR
program\. The default is
\fI\'\. To exclude a database, you would pass \fR\-\-exclude dbname\' here\.
.RE
.PP
\-\-tarfilesuffix=string
.RS 4
Specifies the suffix for the tarball\. The default is
\fI\.tar\.gz\fR\.
.RE
.PP
\-\-rsync=string
.RS 4
Specifies the pathname for the
\fIrsync\fR
program\. The default is
\fIrsync\fR\.
.RE
.PP
\-\-rsyncarg=string
.RS 4
Specifies the arguments for the
\fIrsync\fR
program\. The default is
\fI\-avWP\fR\. Should must ensure that the recursive option is included either implicitly by
\fI\-a\fR, or explicitly\.
.RE
.PP
\-\-xfs
.RS 4
Use the
\fInouuid\fR
mount option to safely mount snapshot partitions that use the XFS file system\.
.RE
.PP
\-\-log_method=string
.RS 4
How to log output from this script\. Valid options are
\fIconsole\fR,
\fIsyslog\fR
or
\fIboth\fR\. The default value is
\fIconsole\fR\.
.RE
.PP
\-\-syslog_socktype=string
.RS 4
What type of socket to use for connecting to the syslog service\. Valid options are
\fInative\fR,
\fItcp\fR
and
\fIudp\fR\. The default value is
\fInative\fR\.
.RE
.PP
\-\-syslog_facility=string
.RS 4
Define a particular syslog facility Default value is the empty string\.
.RE
.PP
\-\-syslog_remotehost=string
.RS 4
Host name of a remote syslog server\.
.RE
.PP
\-\-configfile=string
.RS 4
Specify an alternative configuration file\. The default is
\fI/etc/mylvmbackup\.conf\fR\.
.RE
.PP
\-\-help
.RS 4
Displays a help message showing the available options\.
.RE
.SH "FILES"
.PP
/etc/mylvbackup\.conf
.RS 4
The
\fImylvmbackup\fR
configuration file
.RE
.PP
mylvmbackup
.RS 4
The executable Perl script that performs the work\.
.RE
.SH "REQUIREMENTS"
For proper operation \fImylvmbackup\fR requires Perl 5 with the \fIDBI\fR and \fIDBD::mysql\fR modules\. It also needs the \fIConfig::IniFiles\fR to read the global configuration file of the program and \fISys::Syslog\fR in case you want to enable the syslog log facility\. \fIDate::Format\fR is required to create the time stamp used in the backup file names\. In addition, it utilizes \fIGetopt::Long\fR, \fIFile::Basename\fR and \fIFile::Temp\fR, which usually are part of the default Perl distribution\.
.sp
It also requires several other external programs: GNU \fItar\fR and \fIgzip\fR to back up the data, LVM utilities (\fIlvcreate\fR, \fIlvremove\fR and \fIlvs\fR) to create and remove the LVM snapshot, and the system utilities \fImount\fR and \fIumount\fR\.
.sp
\fIrsync\fR may be used in place of \fItar\fR and \fIgzip\fR\.
.sp
.SH "SEE ALSO"
\fImount(8)\fR, \fItar(1)\fR, \fIlvcreate(8)\fR, \fIlvremove(8)\fR, lvs(8)\fI, \'umount(8)\fR, \fIrsync(1)\fR
.sp
.SH "AUTHOR"
This program was initially written by Aleksey "Walrus" Kishkin from MySQL AB, with suggestions from Peter Zaitsev and Lenz Grimmer\.
.sp
It is currently maintained by Lenz Grimmer, <lenz@grimmer\.com>
.sp
.SH "RESOURCES"
Main web site: http://www\.lenzg\.org/mylvmbackup/ Mailing list: http://www\.freelists\.org/list/mylvmbackup/ Source code, bug tracker: https://launchpad\.net/mylvmbackup/
.sp
.SH "CREDITS"
Several people have contributed to the script since it has been released\. See the ChangeLog for more details\.
.sp
Robin H\. Johnson from the Gentoo project cleaned up the code and added several useful features\.
.sp
Fred Blaise contributed the initial support to use an external configuration file and logging via syslog\.
.sp
Eric Bergen provided the code that performs the InnoDB recovery prior to performing the backup of LVM2 snapshot volumes\. He also fixed the broken handling of default options\.
.sp
Kristian Köhntopp for suggesting the \fI\-\-pidfile\fR option and suggesting to add the output of the LVM statistics for being able to better tune the snapshot size\.
.sp
.SH "COPYING"
mylvmbackup is distributed under the GNU public license\. See the file COPYING for details\.
.sp
.SH "NOTES"
.IP " 1." 4
lenz@grimmer.com>
.RS 4
\%mailto:lenz@grimmer.com>
.RE