Cassandra的備份就是對現有的數據作一個快照,恢復則是把快照進行還原。不只能夠對全庫作快照,也能夠針對表、keyspace單獨作備份。另外它也支持增量備份。java
[root@db03 ~]# nodetool snapshot Requested creating snapshot(s) for [all keyspaces] with snapshot name [1570691336948] and options {skipFlush=false} Snapshot directory: 1570691336948
操做完成後,能夠經過listsnapshots驗證,以下圖所示:
備份完成後,系統會在每一個表所在的目錄下生成一個1570691336948文件夾,裏面存放了每一個表的備份數據。這裏用rhnchecksum表進行說明,以下圖所示:
node
默認狀況下,它的增量備份是禁用的,能夠經過如下命令進行驗證:ide
[root@db03 ~]# nodetool statusbackup not running
啓用增量備份,命令以下:ui
[root@db03 ~]# nodetool enablebackup [root@db03 ~]# nodetool statusbackup running
執行下備份以下:spa
[root@db03 spacewalk]# nodetool snapshot Requested creating snapshot(s) for [all keyspaces] with snapshot name [1570695931097] and options {skipFlush=false} Snapshot directory: 1570695931097
cassandra的恢復過程以下:.net
cqlsh:spacewalk> select count(*) from rhnchecksum; count --------- 8404215 (1 rows) Warnings : Aggregation query used without partition key cqlsh:spacewalk> truncate rhnchecksum; cqlsh:spacewalk> select count(*) from rhnchecksum; count ------- 0 (1 rows)
[root@db03 rhnchecksum-dbbb8330dde111e99dfb45c418aaa2bc]# pwd /var/lib/cassandra/data/spacewalk/rhnchecksum-dbbb8330dde111e99dfb45c418aaa2bc [root@db03 rhnchecksum-dbbb8330dde111e99dfb45c418aaa2bc]# cp -ra snapshots/1570695931097/* . --若是有索引數據也要進行拷貝操做 [root@db03 rhnchecksum-dbbb8330dde111e99dfb45c418aaa2bc]# cp -ra snapshots/1570695931097/.rhnchecksum_idx/* .rhnchecksum_idx/
當把快照文件複製到對應表的目錄下後,運行refresh命令加載新的SSTables 不須要重啓機器節點。日誌
[root@db03 ~]# nodetool refresh spacewalk rhnchecksum --完成後,cassandra的日誌會出現下面的提示: [root@db03 ~]# tail -f /var/log/cassandra/system.log INFO [RMI TCP Connection(68)-127.0.0.1] 2019-10-10 16:41:22,513 ColumnFamilyStore.java:734 - Loading new SSTables for spacewalk/rhnchecksum... INFO [RMI TCP Connection(68)-127.0.0.1] 2019-10-10 16:41:22,517 ColumnFamilyStore.java:782 - Renaming new SSTable /var/lib/cassandra/data/spacewalk/rhnchecksum-dbbb8330dde111e99dfb45c418aaa2bc/md-47-big to /var/lib/cassandra/data/spacewalk/rhnchecksum-dbbb8330dde111e99dfb45c418aaa2bc/md-50-big INFO [RMI TCP Connection(68)-127.0.0.1] 2019-10-10 16:41:22,548 ColumnFamilyStore.java:782 - Renaming new SSTable /var/lib/cassandra/data/spacewalk/rhnchecksum-dbbb8330dde111e99dfb45c418aaa2bc/md-49-big to /var/lib/cassandra/data/spacewalk/rhnchecksum-dbbb8330dde111e99dfb45c418aaa2bc/md-51-big INFO [RMI TCP Connection(68)-127.0.0.1] 2019-10-10 16:41:22,567 ColumnFamilyStore.java:782 - Renaming new SSTable /var/lib/cassandra/data/spacewalk/rhnchecksum-dbbb8330dde111e99dfb45c418aaa2bc/md-48-big to /var/lib/cassandra/data/spacewalk/rhnchecksum-dbbb8330dde111e99dfb45c418aaa2bc/md-52-big INFO [RMI TCP Connection(68)-127.0.0.1] 2019-10-10 16:41:22,589 ColumnFamilyStore.java:782 - Renaming new SSTable /var/lib/cassandra/data/spacewalk/rhnchecksum-dbbb8330dde111e99dfb45c418aaa2bc/md-46-big to /var/lib/cassandra/data/spacewalk/rhnchecksum-dbbb8330dde111e99dfb45c418aaa2bc/md-53-big INFO [RMI TCP Connection(68)-127.0.0.1] 2019-10-10 16:41:22,610 ColumnFamilyStore.java:817 - Loading new SSTables and building secondary indexes for spacewalk/rhnchecksum: [BigTableReader(path='/var/lib/cassandra/data/spacewalk/rhnchecksum-dbbb8330dde111e99dfb45c418aaa2bc/md-52-big-Data.db'), BigTableReader(path='/var/lib/cassandra/data/spacewalk/rhnchecksum-dbbb8330dde111e99dfb45c418aaa2bc/md-51-big-Data.db'), BigTableReader(path='/var/lib/cassandra/data/spacewalk/rhnchecksum-dbbb8330dde111e99dfb45c418aaa2bc/md-53-big-Data.db'), BigTableReader(path='/var/lib/cassandra/data/spacewalk/rhnchecksum-dbbb8330dde111e99dfb45c418aaa2bc/md-50-big-Data.db')] INFO [RMI TCP Connection(68)-127.0.0.1] 2019-10-10 16:41:22,614 SecondaryIndexManager.java:366 - Submitting index build of rhnchecksum_idx for data in BigTableReader(path='/var/lib/cassandra/data/spacewalk/rhnchecksum-dbbb8330dde111e99dfb45c418aaa2bc/md-52-big-Data.db'),BigTableReader(path='/var/lib/cassandra/data/spacewalk/rhnchecksum-dbbb8330dde111e99dfb45c418aaa2bc/md-51-big-Data.db'),BigTableReader(path='/var/lib/cassandra/data/spacewalk/rhnchecksum-dbbb8330dde111e99dfb45c418aaa2bc/md-53-big-Data.db'),BigTableReader(path='/var/lib/cassandra/data/spacewalk/rhnchecksum-dbbb8330dde111e99dfb45c418aaa2bc/md-50-big-Data.db') INFO [Service Thread] 2019-10-10 16:41:34,134 GCInspector.java:284 - ConcurrentMarkSweep GC in 467ms. CMS Old Gen: 1227906720 -> 508200320; Code Cache: 35251328 -> 35276800; Metaspace: 45251080 -> 45251832; Par Eden Space: 6575264 -> 139631912; Par Survivor Space: 41943040 -> 14759936 INFO [Service Thread] 2019-10-10 16:41:43,679 GCInspector.java:284 - ParNew GC in 236ms. CMS Old Gen: 844136912 -> 967814552; Par Eden Space: 335544320 -> 0; Par Survivor Space: 35314704 -> 41943040 INFO [RMI TCP Connection(68)-127.0.0.1] 2019-10-10 16:47:00,987 SecondaryIndexManager.java:386 - Index build of rhnchecksum_idx complete INFO [RMI TCP Connection(68)-127.0.0.1] 2019-10-10 16:47:00,987 ColumnFamilyStore.java:825 - Done loading load new SSTables for spacewalk/rhnchecksum
恢復完成後,驗證數據以下圖所示:
code
nodetool命令的選項中文解釋參考:Cassandra nodetool經常使用操做blog