Percona Xtrabackup on FreeBSD 8.2 - Installation, setting up and basic backups
This is how I got Percona to work on FreeBSD 8.2 - kinda bumpy but looks like it works!
Prerequisites:
- MySQL 5.5 must be installed
- Also, the MySQL configuration file must be in place under /usr/local/etc/my.cnf as in the instructions above as Xtrabackup expectes to find it
1.Start by installing some packages:
pkg_add -r wget bash cmake bazaar
2.Next, download the XtraBackup source into the /tmp directory:
cd /tmp;wget http://www.percona.com/redir/downloads/XtraBackup/XtraBackup-1.6.3/source/xtrabackup-1.6.3.tar.gz
3.Untar the source and enter the directory:
tar xzf xtrabackup-1.6.3.tar.gz;cd xtrabackup-1.6.3
4.The next command will download the only dependency left (MySQL 5.5 Source code (about 23M) and compile xtrabackup against it for the InnoDB5.5 engine. Note, you DO need to do this in the bash shell.
Rehash, then enter the bash shell.
rehash;bash
5.Once in bash:
time AUTO_DOWNLOAD="yes" ./utils/build.sh innodb55
Download the source code plus compiling, took under 4 minutes on my system.
This is what you should see when this is successful:
extract.c:448: warning: incompatible implicit declaration of built-in function 'strlen'gcc -g -O3 -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE -I. -I.. -I. -I../compat -I../listhash -c -o wrapper.o wrapper.c
ar rc libtar.a append.o block.o decode.o encode.o extract.o handle.o libtar_hash.o libtar_list.o output.o util.o wrapper.o
ranlib libtar.a
gmake[1]: Leaving directory `/tmp/xtrabackup-1.6.3/libtar-1.2.11/lib'
gmake[1]: Entering directory `/tmp/xtrabackup-1.6.3/libtar-1.2.11/libtar'
gcc -g -O3 -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE -I.. -I../lib -I../listhash -I../lib -I../compat -c -o libtar.o libtar.c
gcc -g -O3 -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE -o tar4ibd libtar.o ../lib/libtar.a -lz
gmake[1]: Leaving directory `/tmp/xtrabackup-1.6.3/libtar-1.2.11/libtar'
gmake[1]: Entering directory `/tmp/xtrabackup-1.6.3/libtar-1.2.11/doc'
gmake[1]: Nothing to be done for `all'.
gmake[1]: Leaving directory `/tmp/xtrabackup-1.6.3/libtar-1.2.11/doc'
real 1m51.502s
user 1m23.774s
sys 0m14.277s
6.Check compiled xtrabackup version:
/tmp/xtrabackup-1.6.3/mysql-5.5/storage/innobase/xtrabackup/xtrabackup\_innodb55 -v
You should see something like this:
version 1.6.3 for MySQL server 5.5.10 FreeBSD8.2 (i386) (revision id: undefined)
7.Move the files under /usr/local/bin so they're executable from anywhere:
mv /tmp/xtrabackup-1.6.3/mysql-5.5/storage/innobase/xtrabackup/xtrabackup_innodb55 /usr/local/bin/xtrabackup
mv /tmp/xtrabackup-1.6.3/innobackupex /usr/local/bin/innobackupex
Also move the tar4ibd
, which is a special version of tar that knows how to deal with how to handle InnoDB / XtraDB data files correctly.
mv /tmp/xtrabackup-1.6.3/libtar-1.2.11/libtar/tar4ibd /usr/local/bin/tar4ibd
8.Edit the innobackupex script and change the location of the xtrabackup_55
binary:
ee /usr/local/bin/innobackupex
Line 87:
my $option_ibbackup_binary = 'autodetect';
to
my $option\_ibbackup\_binary = '/usr/local/bin/xtrabackup';
9.Try it out: (make sure you've created at least a test database first, else you'll see an error!)
xtrabackup --backup --datadir=/var/db/mysql/ --target-dir=/root/testpercona
If this is successful you should see output like this:
xtrabackup version 1.6.3 for MySQL server 5.5.10 FreeBSD8.2 (i386) (revision id: undefined)
xtrabackup: cd to /var/db/mysql/
xtrabackup: Target instance is assumed as followings.
xtrabackup: innodb_data_home_dir = ./
xtrabackup: innodb_data_file_path = ibdata1:10M:autoextend
xtrabackup: innodb_log_group_home_dir = ./
xtrabackup: innodb_log_files_in_group = 2
xtrabackup: innodb_log_file_size = 5242880
>> log scanned up to (1599186)
[01] Copying ./ibdata1
to /root/testpercona/ibdata1
[01] ...done
xtrabackup: The latest check point (for incremental): '1599186'
>> log scanned up to (1599186)
xtrabackup: Stopping log copying thread.
xtrabackup: Transaction log of lsn (1599186) to (1599186) was copied.
10.Edit the MySQL configuration file:
ee /usr/local/etc/my.cnf
add the line:
datadir=/var/db/mysql
under the [mysqld]
section.
11.Restart MySQL: (before you restart make sure you're not in Bash)
/usr/local/etc/rc.d/mysql-server restart
12.Run the backup script:
innobackupex --defaults-file=/usr/local/etc/my.cnf /root/
the target directory for the backup, in this case, /root directory MUST already exist! (Obviously /root will exist, but make sure whatever you choose in it's place exists already)
You should see output like this - most importantly the 'completed OK!' part!
innobackupex: Resuming ibbackup
xtrabackup: The latest check point (for incremental): '1599186'
>> log scanned up to (1599186)
xtrabackup: Stopping log copying thread.
xtrabackup: Transaction log of lsn (1599186) to (1599186) was copied.
111226 18:50:10 innobackupex: All tables unlocked
111226 18:50:10 innobackupex: Connection to database server closed
innobackupex: Backup created in directory '/root/2011-12-26_18-49-47'
innobackupex: MySQL binlog position: filename '', position
111226 18:50:10 innobackupex: completed OK!
What this command will do is create a subdirectory containing the backup with the timestamp as it's name, for example this is what my /root looks like after the backup:
anubite# ls -al
total 26
drwxr-xr-x 5 root wheel 512 Dec 26 18:58 .
drwxr-xr-x 20 root wheel 512 Dec 14 12:43 ..
-rw------- 1 root wheel 0 Aug 29 22:16 .Xauthority
-rw------- 1 root wheel 1051 Dec 26 18:49 .bash_history
-rw-r--r-- 2 root wheel 798 Feb 17 2011 .cshrc
-rw------- 1 root wheel 1119 Dec 14 12:42 .history
drwxr-xr-x 2 root wheel 512 Aug 29 22:14 .icewm
-rw-r--r-- 1 root wheel 155 Feb 17 2011 .k5login
-rw-r--r-- 1 root wheel 303 Feb 17 2011 .login
-rw------- 1 root wheel 290 Dec 26 18:41 .mysql_history
-rw-r--r-- 2 root wheel 265 Feb 17 2011 .profile
-rw-r--r-- 1 root wheel 29 Aug 29 22:14 .xinitrc
drwxr-xr-x 8 root wheel 512 Dec 26 18:58 2011-12-26_18-58-31
drwx------ 2 root wheel 512 Dec 26 18:57 testpercona
Note the 2011-12-26_18-58-31
directory that is the timestamp of the innobackupscript created backup!
13.Run it again with the --apply-log
option to prepare the backup, in my case it looks like this:
innobackupex --defaults-file=/usr/local/etc/my.cnf --apply-log /root/2011-12-26_18-58-31/
14.Before restoring the backup, stop the database:
/usr/local/etc/rc.d/mysql-server stop
15.Move the existing MySQL files somewhere else just in case:
mv /var/db/mysql/ /root/oldmysqlfiles
16.Create the /var/db/mysql directory again:
mkdir /var/db/mysql
17.To restore the backup:
innobackupex --defaults-file=/usr/local/etc/my.cnf --copy-back /root/2011-12-26_18-58-31
This will bring back the backup from /root/ to /var/db/mysql
You should see something like this if all went well:
innobackupex: Starting to copy InnoDB tables and indexes
innobackupex: in '/root/2011-12-26_18-58-31'
innobackupex: back to original InnoDB data directory '/var/db/mysql'
innobackupex: Copying file '/root/2011-12-26_18-58-31/ibdata1'
innobackupex: Starting to copy InnoDB log files
innobackupex: in '/root/2011-12-26_18-58-31'
innobackupex: back to original InnoDB log directory '/var/db/mysql'
innobackupex: Copying file '/root/2011-12-26_18-58-31/ib_logfile0'
innobackupex: Copying file '/root/2011-12-26_18-58-31/ib_logfile1'
innobackupex: Finished copying back files.
111227 14:52:56 innobackupex: completed OK!
18.Follow this with:
chown -R mysql:mysql /var/db/mysql
19.Start MySQL again:
/usr/local/etc/rc.d/mysql-server start
20.And you're done!