gpt4 book ai didi

linux - cassandra - 将快照拍摄到不同的位置

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:33:40 27 4
gpt4 key购买 nike

我想每 1 小时备份一次 Cassandra 并将其移动到共享位置。

Cassandra 在默认位置拍摄快照,如何在/opt/backup 位置拍摄快照?

最佳答案

你不能(使用快照)。

nodetool snapshot -t <tag> <keyspace>是一个非常简单的工具 - 它只是为您的 key 空间数据目录中的每个文件创建到 snapshots/<tag> 的硬链接(hard link).

因为这些是硬链接(hard link),所以它们必须在同一个文件系统上。这些硬链接(hard link)的好处是快照非常快,并且最初不会消耗额外的磁盘空间(当 sstables 被压缩/删除时,文件保留在快照中)。

如果您希望这些备份位于不同的位置,请使用 -t <tag>创建快照时。我用 demosnapshot 制作了一个演示和一个简单的脚本(没有完全阐述但展示了这个想法:

$ cat cassandrabackup.sh
#!/bin/bash

TAG=`date +%Y%m%d%H%M%S`
BACKUP_LOC=/tmp/backup/`hostname`
KEYSPACE=demokeyspace

echo creating snapshot $TAG
nodetool snapshot -t $TAG $KEYSPACE

echo sync to backup location $BACKUP_LOC
find /var/lib/cassandra -type f -path "*snapshots/$TAG*" -printf %P\\0 | rsync -avP --files-from=- --from0 /var/lib/cassandra/ $BACKUP_LOC

echo removing snapshot $TAG
nodetool clearsnapshot -t $TAG

该脚本创建一个带有特定标签(日期时间)的快照,将内容同步到备份位置,然后删除快照。如果KEYSPACE未定义所有键空间都已备份。

结果是这样的:

$ ./cassandrabackup.sh
creating snapshot 20170823132936
Requested creating snapshot(s) for [demokeyspace] with snapshot name [20170823132936] and options {skipFlush=false}
Snapshot directory: 20170823132936
sync to backup location /tmp/backup/host1.domain.tld
building file list ...
6 files to consider
data1/
data1/demokeyspace/
data1/demokeyspace/demotable-0bbb579087ef11e7aa786377cd3ba823/
data1/demokeyspace/demotable-0bbb579087ef11e7aa786377cd3ba823/snapshots/
data1/demokeyspace/demotable-0bbb579087ef11e7aa786377cd3ba823/snapshots/20170823132936/
data1/demokeyspace/demotable-0bbb579087ef11e7aa786377cd3ba823/snapshots/20170823132936/manifest.json
13 100% 0.00kB/s 0:00:00 (xfr#1, to-chk=0/6)

sent 305 bytes received 50 bytes 710.00 bytes/sec
total size is 13 speedup is 0.04
removing snapshot 20170823132936
Requested clearing snapshot(s) for [all keyspaces] with snapshot name [20170823132936]
$ ifjke@fsca01:~$ find /tmp/backup/
/tmp/backup/
/tmp/backup/host1.domain.tld
/tmp/backup/host1.domain.tld/data2
/tmp/backup/host1.domain.tld/data2/demokeyspace
/tmp/backup/host1.domain.tld/data2/demokeyspace/demotable-0bbb579087ef11e7aa786377cd3ba823
/tmp/backup/host1.domain.tld/data2/demokeyspace/demotable-0bbb579087ef11e7aa786377cd3ba823/snapshots
/tmp/backup/host1.domain.tld/data2/demokeyspace/demotable-0bbb579087ef11e7aa786377cd3ba823/snapshots/20170823125951
/tmp/backup/host1.domain.tld/data2/demokeyspace/demotable-0bbb579087ef11e7aa786377cd3ba823/snapshots/20170823125951/manifest.json
/tmp/backup/host1.domain.tld/data2/demokeyspace/demotable-0bbb579087ef11e7aa786377cd3ba823/snapshots/20170823130014
/tmp/backup/host1.domain.tld/data2/demokeyspace/demotable-0bbb579087ef11e7aa786377cd3ba823/snapshots/20170823130014/manifest.json
/tmp/backup/host1.domain.tld/data1
/tmp/backup/host1.domain.tld/data1/demokeyspace
/tmp/backup/host1.domain.tld/data1/demokeyspace/demotable-0bbb579087ef11e7aa786377cd3ba823
/tmp/backup/host1.domain.tld/data1/demokeyspace/demotable-0bbb579087ef11e7aa786377cd3ba823/snapshots
/tmp/backup/host1.domain.tld/data1/demokeyspace/demotable-0bbb579087ef11e7aa786377cd3ba823/snapshots/20170823132936
/tmp/backup/host1.domain.tld/data1/demokeyspace/demotable-0bbb579087ef11e7aa786377cd3ba823/snapshots/20170823132936/manifest.json
$

因为我过去自己犯过这个错误 - 在备份中包含主机名 ;)

除此之外,cassandra 中还有一个增量备份功能:

http://docs.datastax.com/en/cassandra/3.0/cassandra/operations/opsBackupIncremental.html

关于linux - cassandra - 将快照拍摄到不同的位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45832125/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com