Bug #14594 mysqlhotcopy does not support tar method
Submitted: 2 Nov 2005 23:01 Modified: 5 Dec 2007 18:55
Reporter: Patrick Feliciano Email Updates:
Status: Verified Impact on me:
None 
Category:MySQL Server: Command-line Clients Severity:S4 (Feature request)
Version:4.1.13 OS:Linux (Linux)
Assigned to: CPU Architecture:Any

[2 Nov 2005 23:01] Patrick Feliciano
Description:
Using mysqlhotcopy for backup is nice since it can be done live and quick however it causes quite a bit of disk space to be used as it copies the raw files.  Currently one must perform the hotcopy and then tgz after the fact to try and save space.  Meaning there must be room on your drive for a copy of the entire database and all the final tar.gz files you need.  It would be nice it mysqlhotcopy could spit out the files directly as .tgz files and save alot of space during nightly backups.

How to repeat:
mysqlhotcopy --method="tar zcf" will of course tell you the method is unsupported.

Suggested fix:
I have resolved the issue on my system with the following patch to mysqlhotcopy version 1.22

# diff /usr/bin/mysqlhotcopy /usr/bin/mysqlhotcopy.tar
64c64
<   --method=#           method for copy (only "cp" currently supported)
---
>   --method=#           method for copy ("cp" and "tar" are currently supported)
368a369,374
>     elsif ($opt{method} =~ /^tar\b/)
>     {
>       foreach my $rdb ( @db_desc ) {
>           $rdb->{target} = "$tgt_dirname";
>       }
>     }
423a430,434
>       elsif ($opt{method} =~ /^tar\b/) {
>           my $tar_dirpath = "$rdb->{target}";
>           mkdir($tar_dirpath, 0750) or die "Can't create '$tar_dirpath': $!\n"
>               unless -d $tar_dirpath;
>       }
490c501,505
<   eval { copy_files($opt{method}, \@files, $rdb->{target}, $rdb->{raid_dirs} ); };
---
>   if ( $opt{method} =~ /^tar\b/ ) {
>       eval { copy_files($opt{method}, \@files, $rdb->{target}, $rdb->{raid_dirs}, $rdb->{src} ); };
>   } else {
>       eval { copy_files($opt{method}, \@files, $rdb->{target}, $rdb->{raid_dirs} ); };
>   }
583c598
<     my ($method, $files, $target, $raid_dirs) = @_;
---
>     my ($method, $files, $target, $raid_dirs, $tar_src) = @_;
613a629,646
>     elsif ($method =~ /^tar\b/)  # cp or scp with optional flags
>     {
>         my $tar = $method;
>
>         my @non_raid = map { "'$_'" } grep { ! m:/\d{2}/[^/]+$: } @$files;
>
>         # add files to copy and the destination
>       if (@non_raid) {
>       my $cmd = $tar . " $target" . "/$tar_src.tgz " . "@non_raid";
>       `$cmd`;
>       }
>
>         foreach my $rd ( @$raid_dirs ) {
>             my @raid = map { "'$_'" } grep { m:$rd/: } @$files;
>             print "Tar method does not currently support RAID directories.  RAID files:\n@raid" if ( @raid );
>         }
>     }
>
1138a1172,1173
>
> Patrick Feliciano - Added support for "tar" method.
[2 Jan 2006 14:02] Hartmut Holzgraefe
Hi, could you recreate your patch as a unified diff ("diff -u") and attach it as a file to this bug report?
[3 Jan 2006 6:34] Patrick Feliciano
patch in requested format

Attachment: mysqlhotcopy.tar.patch (text/x-patch), 2.87 KiB.

[3 Jan 2006 21:51] Patrick Feliciano
Added patch file as requested changing status.
[28 Mar 2007 10:01] Harry Bouvarde
Unfortunately, this does not work when the --noindices is used.

I would very much like to use "--noindices" and tar with "tar --use-compress-program=lzop" which provides realtime compression.  That would seem to be the optimal way to perform a mysql backup as quickly as possible (much faster than gzip) with efficient handling of disk space.

If you could update this patch, it would be very much appreciated!  Dumping a 50GB database to disk only to have to read it back in recompress it is... just plain silly.
[2 Jul 2014 11:57] Daniƫl van Eeden
From http://dev.mysql.com/doc/refman/5.6/en/mysqlhotcopy.html
"This utility is deprecated in MySQL 5.6.20 and removed in MySQL 5.7"