man mysqlhotcopy (Commandes) - fast on-line hot-backup utility for local MySQL databases and tables

NAME

mysqlhotcopy - fast on-line hot-backup utility for local MySQL databases and tables

SYNOPSIS

  mysqlhotcopy db_name

  mysqlhotcopy --suffix=_copy db_name_1 ... db_name_n

  mysqlhotcopy db_name_1 ... db_name_n /path/to/new_directory

  mysqlhotcopy db_name./regex/

  mysqlhotcopy db_name./^\(foo\|bar\)/

  mysqlhotcopy db_name./~regex/

  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 \
         db_1./^nice_table/ user@some.system.dom:~/path/to/new_directory
  (INSECURE)

WARNING: THIS PROGRAM IS STILL IN BETA. Comments/patches welcome.

DESCRIPTION

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.

OPTIONS

--checkpoint checkpoint-table
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.table format. The checkpoint-table must contain at least the following fields:
  time_stamp timestamp not null
  src varchar(3)
  dest varchar(6)
  msg varchar(2)
--record_log_pos log-pos-table
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 initialised 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(6) NOT null, time_stamp timestamp(1) NOT NULL, log_file varchar(3) default NULL, log_pos int(1) default NULL, master_host varchar(6) NULL, master_log_file varchar(3) NULL, master_log_pos int NULL,
  PRIMARY KEY  (host) 
);
--suffix suffix
Each database is copied back into the originating datadir under a new name. The new name is the original name with the suffix appended. If only a single db_name is supplied and the --suffix flag is not supplied, then --suffix=_copy is assumed.
--allowold
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 deleted.
--keepold
Behaves as for the --allowold, with the additional feature of keeping the backup directory after the copy successfully completes.
--addtodest
Don't 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 don't want to have all the tables locked for the whole duration. 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.
--flushlog
Rotate the log files by executing FLUSH LOGS after all tables are locked, and before they are copied.
--resetmaster
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.
--resetslave
Reset the master.info by executing RESET SLAVE after all tables are locked, and before they are copied. Useful if you are recovering a server in a mutual replication setup.
--regexp pattern
Copy all databases with names matching the pattern
--regexp /pattern1/./pattern2/
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 with 'foo':
   mysqlhotcopy --indices --method=cp --regexp /foo$/./^bar/
db_name./pattern/
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\)/
db_name./~pattern/
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\)/
-?, --help
Display helpscreen and exit
-u, --user=#
user for database login if not current user
-p, --password=#
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 specifying this different from 'localhost' will trigger mysqlhotcopy to use TCP/IP connection.
-P, --port=#
port to use when connecting to MySQL server with TCP/IP. This is only used when using the --host option.
-S, --socket=#
UNIX domain socket to use when connecting to local server
--noindices
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 myisamchk -r on the backup.
--method=#
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.
-q, --quiet
be silent except for errors
--debug
Debug messages are displayed
-n, --dryrun
Display commands without actually doing them

WARRANTY

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 internals@lists.mysql.com.

TO DO

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-table integrity.

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.

AUTHOR

Tim Bunce

Martin Waite - added checkpoint, flushlog, regexp and dryrun options Fixed cleanup of targets when hotcopy fails. Added --record_log_pos. RAID tables are now copied (don't know if this works over scp).

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 database name(s).

Martin Waite - Fix to handle database name that contains space.

Paul DuBois - Remove end '/' from directory names