项目作者: SeunMatt

项目描述 :
This is a Java library for exporting cassandra database to SQL that can be used to restore an SQL database like MySQL and Postgres
高级语言: Java
项目地址: git://github.com/SeunMatt/cassandra2sql.git
创建时间: 2019-01-02T10:45:18Z
项目社区:https://github.com/SeunMatt/cassandra2sql

开源协议:

下载


Cassandra2SQL

Build Status

This is a simple library for exporting cassandra database to SQL that can be used to restore an SQL database like MySQL and Postgres.

It handles the database columns based on their types i.e. TEXT columns are processed differently from TIMESTAMP type of columns.

Every collection columns, by default, are converted into JSON string

Usage

Requirements

Installed JRE 8+

Verify your installation by running java -version

Running/Executing the Tool

From the command line execute java -jar ./dist/cassandra2sql-1.0.jar application.properties

Where application.properties is the full path to the .properties config file

Configuration

Cassandra2SQL uses application.properties file as a config source. It’s a simple KEY=VALUE entry config file with a .properties extension. So the file can have any name other than application just supply it to the app during execution

TABLE CONFIGURATION

In the config file we can specify the cassandra (source) table we want to export as SQL in the following format:

TABLES=srcTableName1:targetTableName1,srcTableName2:targetTableName2, . . .

The srcTableName is the name of the table to be exported in cassandra, while the targetTableName is the corresponding
table name on the SQL-database (MYSQL/POSTGRES). Multiple tables can be separated with a comma ,

For example, this config will instruct the tool to export the tables user as users, sentmessage as sent_messages and so on.

TABLES=user:users,sentmessage:sent_messages,logs:logs

The SQL insert statement generated will look like INSERT INTO users ..., INSERT INTO sent_messages ... and so on.

COLUMN CONFIGURATION

Next is the column configuration for each tables. The configuration is under the key TABLE_CONFIG_SRCTABLE. It’s a combination of the uppercase format of the srcTableName supplied in the TABLES section.

The value of each table config is the source column name and the target column name separated by the : symbol.

Thus, we can config columns for the users table defined above:

TABLE_CONFIG_USER=firstName:first_name,bvnverified:bvn_verified,emailverified:email_verified,id=:id

For us to configure columns for the logs table, we just need to add this entry to the application.properties file:

TABLE_CONFIG_LOGS=data:data,createdat=created_at,action=action_log

So if we defined 10 tables in the TABLES section, it means we’ll have 10 TABLE_CONFIG_XXX in the configuration file.

More Configuration Properties

  1. #option to either delete the generated zip file or not, default is false
  2. DELETE_GENERATED_ZIPFILE=false
  3. #option to keep the generated sql, default is false as this can lead large memory consumption
  4. KEEP_GENERATED_SQL=false
  5. #the keyspace to connect to
  6. KEYSPACE=claneapp
  7. #the target SQL database. Available options are: POSTGRES or MYSQL
  8. SQL_FLAVOUR=POSTGRES
  9. #the datetime format to use when exporting timestamp columns
  10. DATETIME_FORMAT=yyyy-MM-dd HH:mm:ss
  11. #the date format to use when exporting date comlumns
  12. DATE_FORMAT=yyyy-MM-dd
  13. #database connection configs. If not supplied, 127.0.0.1 is used as the host and 9042 as the port
  14. #with empty username and password
  15. DB_HOST=127.0.0.1
  16. DB_PORT=9042
  17. DB_USERNAME=
  18. DB_PASSWORD=
  19. #minimum email properties required for sending generated zip file to an email address as attachment
  20. #only required if you want generated zip file to be sent to your email
  21. EMAIL_HOST=smtp.mailtrap.io
  22. EMAIL_PORT=25
  23. EMAIL_USERNAME=your-password
  24. EMAIL_PASSWORD=your-username
  25. EMAIL_FROM=seun@example.com
  26. EMAIL_TO=smatt@example.com

Building from Source

Requirements:

  • Apache Maven 3+
  • JRE 8+

Execute mvn clean package and the binary file will be available in target/cassandra2sql-1.0.jar.

To skip tests execute mvn clean package -DskipTests=true

LICENSE

MIT

Author

Seun Matt

Contributing

Found a bug? please create an issue for it with as much details as possible.

Wanna improve the codebase? PRs are welcome