Issue Details (XML | Word | Printable)

Key: HBASE-897
Type: New Feature New Feature
Status: Resolved Resolved
Resolution: Won't Fix
Priority: Minor Minor
Assignee: Unassigned
Reporter: Dan Zinngrabe
Votes: 1
Watchers: 1
Operations

If you were logged in you would be able to see more operations.
Hadoop HBase

Backup/Export/Import Tool

Created: 22/Sep/08 11:01 PM   Updated: 22/Jul/09 10:07 PM
Return to search
Component/s: None
Affects Version/s: 0.1.2, 0.1.3
Fix Version/s: None

Time Tracking:
Not Specified

File Attachments:
  Size
GZip Archive Licensed for inclusion in ASF works hbase_backup_release.tar.gz 2008-09-22 11:03 PM Dan Zinngrabe 8 kB
GZip Archive Licensed for inclusion in ASF works hbase_backup_with_hbase_0.19.x.tar.gz 2009-07-18 06:14 AM atppp 8 kB
Environment: MacOS 10.5.4, CentOS 5.1

Resolution Date: 22/Jul/09 10:07 PM


 Description  « Hide
Attached is a simple import, export, and backup utility. Mahalo.com has been using this in production for several months to back up our HBase clusters as well as to migrate data from production to development clusters, etc.

Documentation included below is from the readme.

HBase Backup
author: Dan Zinngrabe dan@mahalo.com

------------------
Summary:
Simple MapReduce job for exporting data from an HBase table. The exported data is in a simple, flat format that can then be imported using another MapReduce job. This gives you both a backup capability, and a simple way to import and export data from tables.

Backup File Format
------------------

The output of a backup job is a flat text file, or series of flat text files. Each row is represented by a single line, with each item tab delimited. Column names are plain text, while column values are base 64 encoded. This helps us deal with tabs and line breaks in the data. Generally you should not have to worry about this at all.

Setup and installation
------------------

First, make sure your Hadoop installation is properly configured to load the HBase classes. This can easily be done by editing the hadoop-env.sh file to include HBase's jar libraries. You can add the following to hadoop-env.sh to have it load HBase classes:

export HBASE_HOME=/Users/quellish/Desktop/hadoop/hbase-0.1.2
export HADOOP_CLASSPATH=$HBASE_HOME/hbase-0.1.2.jar:$HBASE_HOME/conf:$HBASE_HOME/hbase-0.1.2-test.jar

Second, make sure the hbase-backup.jar file is on the classpath for Hadoop as well. While you can put this into a system-wide class path directory such as ${JAVA_HOME}/lib , it's much easier to just put it into

${HADOOP_HOME}/lib

With that done, you are ready to go. Start up hadoop and HBase normally and you will be able to run a backup and restore.

Backing up
------------------

Backups are run using the Exporter class. From ${HADOOP_HOME} :

bin/hadoop com.mahalo.hadoop.hbase.Exporter -output backup -table text -columns text_flags: text_data:

This will output the backup into the new directory "backup" in the Hadoop File System, and will back up the columns "old_flags" and "old_text", with whatever the table's row identifier is. Colons are required in the column names, and this will produce multiple files in the output directory (simply 'cat' them together to form a single file). Note that if the backup directory exists it will stop. This may be changed in a future version. The output directory can also be any file system path or URL that Hadoop can understand, such as an S3 URL.

Restoring from a backup
------------------

From ${HADOOP_HOME} :

bin/hadoop com.mahalo.hadoop.hbase.Importer backup/backup.tsv text

This will load a single file (that you 'cat'd together from parts), backup/backup.tsv into the table text. Note that the table must already exist, and it can have data in it - those values can be overwritten by the restore process. You can create the table easily using HBase's Shell. The backup file can be loaded from any URL that Hadoop understands, such as a file URL or S3 URL. A path not formatted as URL (such as shown above) assumes a path from your user directory in the hadoop filesystem.

Combining a file from pieces using cat
------------------

As mentioned above, typically a MapReduce job will produce several files of output that must be assembled together to make a single file. On a unix system, this is fairly easy to do, using cat and the find command: First, export your data from the hadoop filesystem to the local filesystem:

bin/hadoop dfs -copyToLocal backup ~/mybackups

Then:

cd ~/
find mybackups/. -name "part-00*" | xargs cat >> backup.tsv

This will take all the files in the "backup" directory matching the pattern "part-00*" and combine them into a file "backup.tsv"

Troubleshooting
------------------

During a restore/import, regionservers splitting or becoming unavailable is normal, and the application will recover from it. You may see errors in the logs, but this is normal.



 All   Comments   Work Log   Change History   Subversion Commits      Sort Order: Ascending order - Click to sort in descending order
Dan Zinngrabe made changes - 22/Sep/08 11:03 PM
Field Original Value New Value
Attachment hbase_backup_release.tar.gz [ 12390698 ]
atppp made changes - 18/Jul/09 06:14 AM
Attachment hbase_backup_with_hbase_0.19.x.tar.gz [ 12413909 ]
Jonathan Gray made changes - 22/Jul/09 10:07 PM
Resolution Won't Fix [ 2 ]
Status Open [ 1 ] Resolved [ 5 ]