项目作者: bobbui

项目描述 :
A highly configurable utility to export whole Apache Cassandra keyspace or table structure/data to CQL scripts.
高级语言: Java
项目地址: git://github.com/bobbui/cassandra-CQL-exporter.git
创建时间: 2016-06-03T10:39:15Z
项目社区:https://github.com/bobbui/cassandra-CQL-exporter

开源协议:Apache License 2.0

下载


Summary

An alternative utility to nodetool snapshot to export whole Apache Cassandra keyspace/table structure and data to Cassandra Query Language (CQL) scripts. CQL scripts is a lightweight,simple way to restore and backup databases.

Features:

  • simple and configurable, see usage for detail.
  • fast and highly scalable: Data is exported gradually, so memory usage is very low, e.g: for my keyspace with 1,5 million record took ~3m to generated.
  • export process is tracked with detail information.
  • CQL scripts is ready to import using SOURCE command.
  • tested with Cassandra > 2.1, 2.2, 3.0 and tick-tock releases.
  • require Java > 6., make sure Java is available in PATH variable.

Overcome nodetool snapshot caveats:

  • snapshot can only be restored when table schema is there —> cassandra-CQL-exporter support both DDL and DML backup.
  • snapshot can only run on a node, multiple node require parallel ssh to be setup —> cassandra-CQL-exporter dont need to care there is how many node.
  • snapshot is stored the node itself, cassandra-CQL-exporter back up is stored on the backup client itself —> more isolated backup environment.

Generated script contains 2 component:

  • DDL: include keyspace CREATE statement, all tables, indexs, materialized views, function, aggregate function, user defined type.
  • DML: INSERT statement for tables data.

Be careful that script will be forward-compatible but not guarantee to be backward-compatible especially DDL statements. It’s better that export and import using same Cassandra version.
I’m using this on a daily basis. But anyways, use this at YOUR OWN RISK!

Usage

  1. usage: cql-export [--drop] [-f <file name>] [-fo] [-h <host>] [--help] [-k <keyspace>] [-l] [-m]
  2. [--noddl] [--nodml] [-p <password>] [-po <port>] [-s] [-t <table>] [--test] [--truncate] [-u
  3. <username>] [-v] [--secure]
  4. --drop add DROP KEYSPACE statement. BE CAREFUL! THIS WILL WIPED OUT ENTIRE
  5. KEYSPACE
  6. -f,--file <file name> exported file path. default to "<keyspace>.CQL" or
  7. "<keyspace>.<table>.CQL"
  8. -fo,--force force overwrite of existing file
  9. -h,--host <host> server host name or IP of database server, default is "localhost"
  10. --help print this help message
  11. -k,--keyspace <keyspace> database keyspace to be exported.
  12. or <keyspace1,keyspace2> It allows to specify multiple keyspaces separated with comma. e.g. -k keyspace1,keyspace2
  13. -kf,--keyspacesFile Allows to specify file which contains keyspaces you'd like to export, separated by new line
  14. -l,--license Print this software license
  15. -m,--merge merge table data, insert will be generated with "IF NOT EXISTS"
  16. --noddl don't generate DDL statements (CREATE TABLE, INDEX, MATERIALIZED VIEW,
  17. TYPE, TRIGGER, AGGREGATE), mutual exclusive with "nodml" option
  18. --nodml don't generate DML statements (INSERT), mutual exclusive with "noddl"
  19. option
  20. -p,--pass <password> database password
  21. -po,--port <port> database server port, default is 9042
  22. -s,--separate seperated export by tables
  23. -t,--table <table> keyspace table to be exported
  24. --test Enable test mode. for development testing only
  25. --truncate add TRUNCATE TABLE statement. BE CAREFUL!
  26. -u,--user <username> database username
  27. -v,--verbose print verbose message
  28. --secure connect via SSL, -Djavax.net.ssl.trustStore=... -Djavax.net.ssl.trustStorePassword=...
  29. must be added to JAVA_OPTS environment variable

Sample usage

  1. Simplest usages; only keyspace needed with localhost server and default port

    1. $cql-export -k cycling
    2. Trying connect to host "localhost"
    3. Success!
    4. Trying connect to port "9042"
    5. Success!
    6. Trying connect to keyspace "cycling"
    7. Success!
    8. All good!
    9. Start exporting...
    10. Write DDL to C:\cql-generator\cycling.CQL
    11. Extract from cycling.cyclist_races
    12. Total number of record: 117920
    13. Start write "cyclist_teams" data DML to C:\cql-generator\cycling.CQL
    14. Done 5.00%
    15. Done 30.00%
    16. Done 90.00%
    17. Done exporting "cyclist_teams", total number of records exported: 117920
    18. Export completed after 21.179 s!
    19. Exited.
  2. Simple usage:

    1. $cql-export -h localhost-po 9043 -k cycling
  3. Generate only DDL statement
    1. $cql-export -h localhost-po 9043 -k keyspace_name -noddl

    TODO

    TODO: optimized jar size.

    License

    Apache 2.0 License

Using gradle

Run

  1. ./gradlew

or (Windows:)

  1. gradlew.bat

Build jar file

  1. ./gradlew jar

or (Windows:)

  1. gradlew.bat jar

this places the jar file into the “dist” folder

Change log

version 1.1 with gradle script and possibility to specify multiple keyspaces to export
contributed by matto3c https://www.codegravity.com