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:
- shut down the node
- clear out the old commitlog and sstables
- 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
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/23937368/viewspace-1051061/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/23937368/viewspace-1051061/
本文介绍了如何使用Cassandra的nodetool snapshot命令进行在线数据快照,以及如何备份和恢复这些快照。同时,文章还讨论了在某些操作系统/JVM组合下可能遇到的内存分配错误,并提供了解决方案。
419

被折叠的 条评论
为什么被折叠?



