ITPub博客

首页 > 应用开发 > IT综合 > cassandra backup

cassandra backup

原创 IT综合 作者:oxoxooxx 时间:2011-06-11 23:43:45 0 删除 编辑

Backing up data

Cassandra can snapshot data while online using nodetool snapshot. You can then back up those snapshots using any desired system, although leaving them where they are is probably the option that makes the most sense on large clusters. nodetool snapshot triggers a node-wide flush, so all data written before the execution of the snapshot command is contained within the snapshot.

With some combinations of operating system/jvm you may receive an error related to the inability to create a process during the snapshotting, such as this on Linux

Exception in thread "main" java.io.IOException: Cannot run program "ln": java.io.IOException: error=12, Cannot allocate memory

This is caused by the operating system trying to allocate the child "ln" process a memory space as large as the parent process (the cassandra server), even though it's not going to use it. So if you have a machine with 8GB of RAM and no swap, and you gave 6GB to the cassandra server, it will fail during this because the operating system wants 12 GB of virtual memory before allowing you to create the process.

This error can be worked around by either :

  • dropping the jna.jar file into Cassandra's lib folder (requires at least Cassandra 0.6.6)

OR

  • creating a swap file, snapshotting, removing swap file

OR

  • turning on "memory overcommit"

To restore a snapshot:

  1. shut down the node
  2. clear out the old commitlog and sstables
  3. move the sstables from the snapshot location to the live data directory.

Consistent backups

You can get an eventually consistent backup by snapshotting all node; no individual node's backup is guaranteed to be consistent but if you restore from that snapshot then clients will get eventually consistent behavior as usual.

There is no such thing as a consistent view of the data in the strict sense, except in the trivial case of writes with consistency level = ALL.

-------------------------------test---------------------------------

restore:
1.stop node
pgep -u `whoami` -f cassandra |xargs kill -9
2.clean commitlog and sstable
rm -f /var/lib/cassandra/commitlog/*
rm -f /dir/*
3.
cp /var/lib/cassandra/data/demo/snapshots/oxoxooxx/* /var/lib/cassandra/data/demo/
cp /var/lib/cassandra/data/demo/backups/* /var/lib/cassandra/data/demo/
4.
./cassandra
./cassandra-cli -h 192.168.100.110 -p 9160

[@more@]

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/23937368/viewspace-1051061/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论
  • 博文量
    178
  • 访问量
    843651