如何恢复Cassandra快照? [英] How can I restore Cassandra snapshots?

查看:2107
本文介绍了如何恢复Cassandra快照?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在建立一个Cassandra数据库的备份和恢复过程,以便在我需要时准备好,以便我了解详细信息,以便构建可用于生产的东西。我在这里按照Datastax的说明:

I'm building a backup and restore process for a Cassandra database so that it's ready when I need it, and so that I understand the details in order to build something that will work for production. I'm following Datastax's instructions here:

http://www.datastax.com/documentation/cassandra/2.0/cassandra/operations/ops_backup_restore_c.html

作为开始,我在一个dev盒中的数据库,然后尝试使备份/恢复工作。以下是备份脚本:

As a start, I'm seeding the database on a dev box then attempting to make the backup/restore work. Here's the backup script:

#!/bin/bash

cd /opt/apache-cassandra-2.0.9
./bin/nodetool clearsnapshot -t after_seeding makeyourcase
./bin/nodetool snapshot -t after_seeding makeyourcase

cd /var/lib/
tar czf after_seeding.tgz cassandra/data/makeyourcase/*/snapshots/after_seeding

最有效的方式,也许,但我只是想让一些工作,现在。

Yes, tar is not the most efficient way, perhaps, but I'm just trying to get something working right now. I've checked the tar, and all the files are there.

备份数据库后,我关闭了Cassandra和我的应用程序,然后 rm -rf / var / lib / cassandra / 以模拟完全丢失。

Once the database is backed up, I shut down Cassandra and my app, then rm -rf /var/lib/cassandra/ to simulate a complete loss.

http://www.datastax.com/documentation/cassandra/恢复方法2 2.0 / cassandra / operations / ops_backup_snapshot_restore_t.html 与方法1更符合我的模式创建组件。

Now to restore the database. Restoration "Method 2" from http://www.datastax.com/documentation/cassandra/2.0/cassandra/operations/ops_backup_snapshot_restore_t.html is more compatible with my schema-creation component than Method 1.

所以,方法2 /步骤1,重新创建模式:重新启动Cassandra,然后是我的应用程序。该应用程序被构建为在必要时在启动时重新重新创建模式。一旦它开始,有一个工作Cassandra节点与应用程序的模式,但没有数据。

So, Method 2/Step 1, "Recreate the schema": Restart Cassandra, then my app. The app is built to re-recreate the schema on startup when necessary. Once it's up, there's a working Cassandra node with a schema for the app, but no data.

方法2 /步骤2恢复快照:他们给出三个选择,第一个是使用sstableloader,记录在 http://www.datastax。 com / documentation / cassandra / 2.0 / cassandra / tools / toolsBulkloader_t.html 。加载程序需要的文件夹结构与快照工具创建的文件夹结构不同,因此所有内容都必须移动到位。在处理所有这些麻烦之前,我只需在一个表上尝试:

Method 2/Step 2 "Restore the snapshot": They give three alternatives, the first of which is to use sstableloader, documented at http://www.datastax.com/documentation/cassandra/2.0/cassandra/tools/toolsBulkloader_t.html. The folder structure that the loader requires is nothing like the folder structure created by the snapshot tool, so everything has to be moved into place. Before going to all that trouble, I'll just try it out on one table:

>./bin/sstableloader makeyourcase/users
Error: Could not find or load main class org.apache.cassandra.tools.BulkLoader



嗯,好吧,这不会工作。 BulkLoader在./lib/apache-cassandra-2.0.9.jar中,但加载器似乎没有设置为开箱即用。而不是调试工具,让我们继续第二个选择,将快照目录复制到makeyourcase / users / snapshots /目录。这应该很容易,因为我们把快照目录直接放到它来自哪里,所以 tar xzf after_seeding.tgz 应该做的诀窍:

cd /var/lib/
tar xzf after_seeding.tgz
chmod -R u+rwx cassandra/data/makeyourcase

,并将快照目录放回到各自的snapshots目录下,刷新应该恢复数据:

and that puts the snapshot directories back under their respective 'snapshots' directories, and a refresh should restore the data:

cd /opt/apache-cassandra-2.0.9
./bin/nodetool refresh -- makeyourcase users

这没有任何投诉。注意,你必须为每个表运行这个,所以你必须先生成表的列表。但是,在我们这样做之前,注意有一些有趣的Cassandra日志:

This runs without complaint. Note that you have to run this for each and every table, so you have to generate the list of tables first. But, before we do that, note that there's something interesting in the Cassandra logs:

INFO 14:32:26,319 Loading new SSTables for makeyourcase/users...
INFO 14:32:26,326 No new SSTables were found for makeyourcase/users

所以,我们把快照,但Cassandra没有找到它。我还尝试移动现有SSTables目录下的快照目录,并将旧的SSTable文件复制到现有目录中,在日志中出现相同的错误。 Cassandra不会记录它希望找到的地方,只是它找不到它们。文档说他们把它们放在一个名为data / keyspace / table_name-UUID的目录,但没有这样的目录。有一个命名的数据/ makeyourcase / users / snapshots / 1408820504987-users /,但将快照目录放在那里,或单个文件,没有工作。

So, we put the snapshot back, but Cassandra didn't find it. I also tried moving the snapshot directory under the existing SSTables directory, and copying the old SSTable files into the existing directory, with the same error in the log. Cassandra doesn't log where it expects to find them, just that it can't find them. The docs say to put them into a directory named data/keyspace/table_name-UUID, but there is no such directory. There is one named data/makeyourcase/users/snapshots/1408820504987-users/, but putting the snapshot dir there, or the individual files, didn't work.

第三个选择,节点重启方法看起来不适合多节点生产环境,所以我没有尝试。

The third alternative, the "Node restart method" doesn't look suitable for a multi-node production environment, so I didn't try that.

编辑:

为了让下一个人完全明确,下面是应用接受的答案的初步的,可用的备份和恢复脚本。

Just to make this perfectly explicit for the next person, here are the preliminary, working backup and restore scripts that apply the accepted answer.

myc_backup.sh:

myc_backup.sh:

#!/bin/bash

cd ~/bootstrap/apache-cassandra-2.0.9
./bin/nodetool clearsnapshot -t after_seeding makeyourcase
./bin/nodetool snapshot -t after_seeding makeyourcase

cd /var/lib/
tar czf after_seeding.tgz cassandra/data/makeyourcase/*/snapshots/after_seeding

myc_restore .sh:

myc_restore.sh:

#!/bin/bash

cd /var/lib/
tar xzf after_seeding.tgz
chmod -R u+rwx cassandra/data/makeyourcase

cd ~/bootstrap/apache-cassandra-2.0.9
TABLE_LIST=`./bin/nodetool cfstats makeyourcase | grep "Table: " | sed -e 's+^.*: ++'`
for TABLE in $TABLE_LIST; do
    echo "Restore table ${TABLE}"
    cd /var/lib/cassandra/data/makeyourcase/${TABLE}
    if [ -d "snapshots/after_seeding" ]; then
        cp snapshots/after_seeding/* .
        cd ~/bootstrap/apache-cassandra-2.0.9
        ./bin/nodetool refresh -- makeyourcase ${TABLE}
        cd /var/lib/cassandra/data/makeyourcase/${TABLE}
        rm -rf snapshots/after_seeding
        echo "    Table ${TABLE} restored."
    else
        echo "    >>> Nothing to restore."
    fi
done


推荐答案

更多详细信息:

您可以使用以下命令运行特定键空间的快照:

You can run the snapshot for your particular keyspace using:

$ nodetool snapshot <mykeyspace> -t <SnapshotDirectoryName>

这将在数据快照目录中创建快照文件。

This will create the snapshot files inside the snapshots directory in data.

当您删除数据时,确保不要删除快照文件夹,否则您将无法恢复它(除非您将其移动到其他位置/机器)。

When you delete your data, make sure you don't delete the snapshots folder or you will not be able to restore it (unless you are moving it to another location / machine.)

$ pwd
/var/lib/cassandra/data/mykeyspace/mytable
$ ls
mykeyspace-mytable-jb-2-CompressionInfo.db mykeyspace-mytable-jb-2-Statistics.db
mykeyspace-mytable-jb-2-Data.db mykeyspace-mytable-jb-2-Filter.db mykeyspace-mytable-jb-2-Index.db
mykeyspace-mytable-jb-2-Summary.db mykeyspace-mytable-jb-2-TOC.txt snapshots


$ rm *
rm: cannot remove `snapshots': Is a directory

一次您已准备好恢复,将快照数据复制回到keyspace / table目录(每个表一个):

Once you are ready to restore, copy back the snapshot data into the keyspace/table directory (one for each table):

$ pwd
/var/lib/cassandra/data/mykeyspace/mytable
$ sudo cp snapshots/<SnapshotDirectoryName>/* .

您提到:


,并将快照目录放回各自的快照目录下,并且refresh>应该恢复数据:

and that puts the snapshot directories back under their respective 'snapshots' directories, and a refresh >should restore the data:

我认为问题是,您正在将快照数据还原到快照目录中。它应该在表目录中。一切似乎都对,让我知道。

I think the issue is that you are restoring the Snapshot data into the snapshot directory. It should go right in the table directory. Everything else seems right, let me know.

这篇关于如何恢复Cassandra快照?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆