--- vzdump.orig	2012-02-09 21:07:40.346419431 +0200
+++ vzdump	2012-02-09 23:21:05.110434357 +0200
@@ -63,6 +63,8 @@
 		'maxfiles=i',
 		'script=s',
 		'storage=s',
+		'mysql-vmid=s@',
+		'mysql-default-file=s',
 		);
 
 sub print_usage {
@@ -71,27 +73,31 @@
     print STDERR "ERROR: $msg\n\n" if $msg;
 
     print STDERR "usage: $0 OPTIONS [--all | VMID]\n\n";
-    print STDERR "\t--exclude VMID\t\texclude VMID (assumes --all)\n";
-    print STDERR "\t--exclude-path REGEX\texclude certain files/directories\n";     print STDERR "\t--stdexcludes\t\texclude temorary files and logs\n\n";
+    print STDERR "\t--exclude VMID\t\t\texclude VMID (assumes --all)\n";
+    print STDERR "\t--exclude-path REGEX\t\texclude certain files/directories\n";
+    print STDERR "\t--stdexcludes\t\t\texclude temorary files and logs\n\n";
  
-    print STDERR "\t--compress\t\tcompress dump file (gzip)\n";
-    print STDERR "\t--dumpdir DIR\t\tstore resulting files in DIR\n";
-    print STDERR "\t--maxfiles N\t\tmaximal number of backup files per VM\n";
-    print STDERR "\t--script FILENAME\texecute hook script\n"; 
-    print STDERR "\t--storage STORAGE_ID\tstore resulting files to STORAGE_ID (PVE only)\n";
-    print STDERR "\t--tmpdir DIR\t\tstore temporary files in DIR\n\n";
-
-    print STDERR "\t--mailto EMAIL\t\tsend notification mail to EMAIL.\n";
-    print STDERR "\t--quiet\t\t\tbe quiet.\n";
-    print STDERR "\t--stop\t\t\tstop/start VM if running\n";
-    print STDERR "\t--suspend\t\tsuspend/resume VM when running\n";
-    print STDERR "\t--snapshot\t\tuse LVM snapshot when running\n";
-    print STDERR "\t--size MB\t\tLVM snapshot size\n\n";
-
-    print STDERR "\t--node CID\t\tonly run on pve cluster node CID\n";
-    print STDERR "\t--lockwait MINUTES\tmaximal time to wait for the global lock\n";
-    print STDERR "\t--stopwait MINUTES\tmaximal time to wait until a VM is stopped\n";
-    print STDERR "\t--bwlimit KBPS\t\tlimit I/O bandwidth; KBytes per second\n\n";
+    print STDERR "\t--compress\t\t\tcompress dump file (gzip)\n";
+    print STDERR "\t--dumpdir DIR\t\t\tstore resulting files in DIR\n";
+    print STDERR "\t--maxfiles N\t\t\tmaximal number of backup files per VM\n";
+    print STDERR "\t--script FILENAME\t\texecute hook script\n"; 
+    print STDERR "\t--storage STORAGE_ID\t\tstore resulting files to STORAGE_ID (PVE only)\n";
+    print STDERR "\t--tmpdir DIR\t\t\tstore temporary files in DIR\n\n";
+
+    print STDERR "\t--mailto EMAIL\t\t\tsend notification mail to EMAIL.\n";
+    print STDERR "\t--quiet\t\t\t\tbe quiet.\n";
+    print STDERR "\t--stop\t\t\t\tstop/start VM if running\n";
+    print STDERR "\t--suspend\t\t\tsuspend/resume VM when running\n";
+    print STDERR "\t--snapshot\t\t\tuse LVM snapshot when running\n";
+    print STDERR "\t--size MB\t\t\tLVM snapshot size\n\n";
+
+    print STDERR "\t--node CID\t\t\tonly run on pve cluster node CID\n";
+    print STDERR "\t--lockwait MINUTES\t\tmaximal time to wait for the global lock\n";
+    print STDERR "\t--stopwait MINUTES\t\tmaximal time to wait until a VM is stopped\n";
+    print STDERR "\t--bwlimit KBPS\t\t\tlimit I/O bandwidth; KBytes per second\n\n";
+
+    print STDERR "\t--mysql-vmid VMID\t\tMySQL VMID\n";
+    print STDERR "\t--mysql-default-file FILE\tMySQL read default options from the given file\n";
 
     print STDERR "\n";
 }
@@ -133,7 +139,9 @@
 
 $opts->{vmids} = PVE::VZDump::check_vmids (@ARGV) if !$opts->{all};
 
-$opts->{exclude} =  PVE::VZDump::check_vmids (@{$opts->{exclude}}) if $opts->{exclude};
+$opts->{exclude} = PVE::VZDump::check_vmids (@{$opts->{exclude}}) if $opts->{exclude};
+
+$opts->{'mysql-vmid'} = PVE::VZDump::check_vmids (@{$opts->{'mysql-vmid'}}) if $opts->{'mysql-vmid'};
 
 my $vzdump = PVE::VZDump->new ($cmdline, $opts);
 
@@ -163,48 +171,52 @@
 
 vzdump OPTIONS [--all | <VMID>]
 
---exclude VMID          exclude VMID (assumes --all)
+--exclude VMID              exclude VMID (assumes --all)
 
---exclude-path REGEX    exclude certain files/directories. You 
-                        can use this option more than once to specify 
-                        multiple exclude paths
+--exclude-path REGEX        exclude certain files/directories. You 
+                            can use this option more than once to specify 
+                            multiple exclude paths
 
---stdexcludes           exclude temporary files and logs
+--stdexcludes               exclude temporary files and logs
 
---compress              compress dump file (gzip)
+--compress                  compress dump file (gzip)
 
---storage STORAGE_ID    store resulting files to STORAGE_ID (PVE only)
+--storage STORAGE_ID        store resulting files to STORAGE_ID (PVE only)
 
---script                execute hook script
+--script                    execute hook script
 
---dumpdir DIR           store resulting files in DIR
+--dumpdir DIR               store resulting files in DIR
 
---maxfiles N            maximal number of backup files per VM.
+--maxfiles N                maximal number of backup files per VM.
 
---tmpdir DIR            store temporary files in DIR. --suspend and --stop
-                        are using this directory to store a copy of the VM.
+--tmpdir DIR                store temporary files in DIR. --suspend and --stop
+                            are using this directory to store a copy of the VM.
 
---mailto EMAIL          send notification mail to EMAIL. You can use 
-                        this option more than once to specify multiple 
-                        receivers
+--mailto EMAIL              send notification mail to EMAIL. You can use 
+                            this option more than once to specify multiple 
+                            receivers
 
---stop                  stop/start VM if running
+--stop                      stop/start VM if running
 
---suspend               suspend/resume VM when running
+--suspend                   suspend/resume VM when running
 
---snapshot              use LVM snapshot when running
+--snapshot                  use LVM snapshot when running
 
---size MB               LVM snapshot size (default 1024)
+--size MB                   LVM snapshot size (default 1024)
     
---bwlimit KBPS          limit I/O bandwidth; KBytes per second
+--bwlimit KBPS              limit I/O bandwidth; KBytes per second
+
+--lockwait MINUTES          maximal time to wait for the global
+                            lock. vzdump uses a global lock file to make
+                            sure that only one instance is running
+                            (running several instance puts too much load
+                            on a server). Default is 180 (3 hours).
+
+--stopwait MINUTES          maximal time to wait until a VM is stopped.
 
---lockwait MINUTES      maximal time to wait for the global
-                        lock. vzdump uses a global lock file to make
-                        sure that only one instance is running
-                        (running several instance puts too much load
-                        on a server). Default is 180 (3 hours).
+--mysql-vmid VMID           MySQL VMID
 
---stopwait MINUTES      maximal time to wait until a VM is stopped.
+--mysql-default-file FILE   MySQL read default options from the given file
 
 =head1 DESCRIPTION
 
@@ -280,6 +292,29 @@
  maxfiles: N
  script: FILENAME
 
+=head1 MYSQL BACKUP
+
+To create consistent MySQL VM backup vzdump can flush all MySQL server caches to disk, obtain a read lock before creating LVM snapshot and then unlock 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 backup proceeds.
+
+The following parameters must be specified:
+
+ --mysql-vmid VMID           MySQL VMID
+ --mysql-default-file FILE   MySQL read default options from the given file
+
+Configuration example /etc/mysql/vzdump.cnf (client section mandatory and must be first):
+
+ [client]
+ host     = localhost
+
+ [777]
+ host     = 1.1.1.7
+ user     = backup
+ password = secret
+
+For security reasons never run backup as root. To create MySQL backup user use the following query:
+
+ GRANT SELECT, LOCK TABLES, RELOAD TO backup@'%' IDENTIFIED BY 'secret';
+
 =head1 HOOK SCRIPT
 
 You can specify a hook script with option C<--script>. This script is called at various phases of the backup process, with parameters accordingly set. You can find an example in the documentation directory (C<hook-script.pl>). 
