MYSQLHOTCOPY(1) User Contributed Perl Documentation MYSQLHOTCOPY(1)
mysqlhotcopy - fast on-line hot-backup utility for local MySQL
databases and tables
mysqlhotcopy --suffix=_copy db_name_1 ... db_name_n
mysqlhotcopy db_name_1 ... db_name_n /path/to/new_directory
mysqlhotcopy db_name_1./regex_1/ db_name_1./regex_2/ ... db_name_n./regex_n/ /path/to/new_directory
mysqlhotcopy --method=scp -Bq -i /usr/home/foo/.ssh/identity --user=root --password=secretpassword \
WARNING: THIS PROGRAM IS STILL IN BETA. Comments/patches welcome.
mysqlhotcopy is designed to make stable copies of live MySQL databases.
Here "live" means that the database server is running and the database
may be in active use. And "stable" means that the copy will not have
any corruptions that could occur if the table files were simply copied
without first being locked and flushed from within the server.
As each database is copied, an entry is written to the specified
checkpoint-table. This has the happy side-effect of updating the
MySQL update-log (if it is switched on) giving a good indication of
where roll-forward should begin for backup+rollforward schemes.
The name of the checkpoint table should be supplied in database.ta
ble format. The checkpoint-table must contain at least the follow
time_stamp timestamp not null
Just before the database files are copied, update the record in the
log-pos-table from the values returned from "show master status"
and "show slave status". The master status values are stored in the
log_file and log_pos columns, and establish the position in the
binary logs that any slaves of this host should adopt if ini
tialised from this dump. The slave status values are stored in
master_host, master_log_file, and master_log_pos, and these are
useful if the host performing the dump is a slave and other sibling
slaves are to be initialised from this dump.
The name of the log-pos table should be supplied in database.table
format. A sample log-pos table definition:
CREATE TABLE log_pos (
host varchar(60) NOT null,
time_stamp timestamp(14) NOT NULL,
log_file varchar(32) default NULL,
log_pos int(11) default NULL,
master_host varchar(60) NULL,
master_log_file varchar(32) NULL,
master_log_pos int NULL,
PRIMARY KEY (host)
Each database is copied back into the originating datadir under a
new name. The new name is the original name with the suffix
If only a single db_name is supplied and the --suffix flag is not
supplied, then "--suffix=_copy" is assumed.
Move any existing version of the destination to a backup directory
for the duration of the copy. If the copy successfully completes,
the backup directory is deleted - unless the --keepold flag is set.
If the copy fails, the backup directory is restored.
The backup directory name is the original name with "_old"
appended. Any existing versions of the backup directory are
Behaves as for the --allowold, with the additional feature of keep
ing the backup directory after the copy successfully completes.
Dont rename target directory if it already exists, just add the
copied files into it.
This is most useful when backing up a database with many large
tables and you dont want to have all the tables locked for the
In this situation, if you are happy for groups of tables to be
backed up separately (and thus possibly not be logically consistant
with one another) then you can run mysqlhotcopy several times on
the same database each with different db_name./table_regex/. All
but the first should use the --addtodest option so the tables all
end up in the same directory.
Rotate the log files by executing "FLUSH LOGS" after all tables are
locked, and before they are copied.
Reset the bin-log by executing "RESET MASTER" after all tables are
locked, and before they are copied. Useful if you are recovering a
slave in a replication setup.
Reset the master.info by executing "RESET SLAVE" after all tables
are locked, and before they are copied. Useful if you are recover
ing a server in a mutual replication setup.
Copy all databases with names matching the pattern
Copy all tables with names matching pattern2 from all databases
with names matching pattern1. For example, to select all tables
which names begin with bar from all databases which names end
mysqlhotcopy --indices --method=cp --regexp /foo$/./^bar/
Copy only tables matching pattern. Shell metacharacters ( (, ), |,
!, etc.) have to be escaped (e.g. \). For example, to select all
tables in database db1 whose names begin with foo or bar:
mysqlhotcopy --indices --method=cp db1./^\(foo\|bar\)/
Copy only tables not matching pattern. For example, to copy tables
that do not begin with foo nor bar:
mysqlhotcopy --indices --method=cp db1./~^\(foo\|bar\)/
Display helpscreen and exit
user for database login if not current user
password to use when connecting to the server. Note that you are
strongly encouraged *not* to use this option as every user would be
able to see the password in the process list. Instead use the
[mysqlhotcopy] section in one of the config files, normally
/etc/my.cnf or your personal ~/.my.cnf. (See the chapter my.cnf
Option Files in the manual)
WARNING: Providing a password on command line is insecure as it is
visible through /proc to anyone for a short time.
-h, -h, --host=#
Hostname for local server when connecting over TCP/IP. By specify
ing this different from localhost will trigger mysqlhotcopy to
use TCP/IP connection.
port to use when connecting to MySQL server with TCP/IP. This is
only used when using the --host option.
UNIX domain socket to use when connecting to local server
Don\t include index files in copy. Only up to the first 2048 bytes
are copied; You can restore the indexes with isamchk -r or myisam
chk -r on the backup.
method for copy (only "cp" currently supported). Alpha support for
"scp" was added in November 2000. Your experience with the scp
method will vary with your ability to understand how scp works.
man scp and man ssh are your friends.
The destination directory _must exist_ on the target machine using
the scp method. --keepold and --allowold are meaningless with scp.
Liberal use of the --debug option will help you figure out what\s
really going on when you do an scp.
Note that using scp will lock your tables for a _long_ time unless
your network connection is _fast_. If this is unacceptable to you,
use the cp method to copy the tables to some temporary area and
then scp or rsync the files at your leisure.
be silent except for errors
Debug messages are displayed
Display commands without actually doing them
This software is free and comes without warranty of any kind. You
should never trust backup software without studying the code yourself.
Study the code inside this script and only rely on it if you believe
that it does the right thing for you.
Patches adding bug fixes, documentation and new features are welcome.
Please send these to firstname.lastname@example.org.
Extend the individual table copy to allow multiple subsets of tables to
be specified on the command line:
mysqlhotcopy db newdb t1 t2 /^foo_/ : t3 /^bar_/ : +
where ":" delimits the subsets, the /^foo_/ indicates all tables with
names begining with "foo_" and the "+" indicates all tables not copied
by the previous subsets.
newdb is either another not existing database or a full path to a
directory where we can create a directory db
Add option to lock each table in turn for people who don\t need cross-
Add option to FLUSH STATUS just before UNLOCK TABLES.
Add support for other copy methods (eg tar to single file?).
Add support for forthcoming MySQL RAID table subdirectory layouts.
Martin Waite - added checkpoint, flushlog, regexp and dryrun options
Fixed cleanup of targets when hotcopy fails.
RAID tables are now copied (dont know if this works
Ralph Corderoy - added synonyms for commands
Scott Wiersdorf - added table regex and scp support
Monty - working --noindex (copy only first 2048 bytes of index file)
Fixes for --method=scp
Ask Bjoern Hansen - Cleanup code to fix a few bugs and enable -w again.
Emil S. Hansen - Added resetslave and resetmaster.
Jeremy D. Zawodny - Removed depricated DBI calls. Fixed bug which
resulted in nothing being copied when a regexp was specified but no
Martin Waite - Fix to handle database name that contains space.
Paul DuBois - Remove end / from directory names
perl v5.8.8 2008-01-27 MYSQLHOTCOPY(1)