经验大分享:TDB文件介绍

简介: 经验大分享:TDB文件介绍

samba在运行时,Samba 存储许多信息,从本地密码到希望从中收到信息的一系列客户端。这类数据其中一些是暂时的,在 Samba 重启时可能会被丢弃,但是另一些却是永久的,不会被丢弃。这类数据可能是很大的,也可能是不经常访问只是在内存中保留,或者在重启时保持存在。要满足这些要求,Samba 团队创建了 Trivial Database。它实际上是一个键值存储,这意味着数据通过惟一键的方式存储和检索,且没有像在关系数据库中那样的表联接。键值存储 — 尤其是 TDB — 被设计成将数据存储到磁盘并将其取回的一种快速方式。

查看samba下tdb文件,只列出/var/lib/samba下面的,还有很多其他目录存在samba tdb文件。

【root@node1 samba】# cd /var/lib/samba/

【root@node1 samba】# ll

total 2236

-rw——- 1 root root 421888 Apr 23 15:10 account_policy.tdb

drwxr-xr-x 1 root root 0 Nov 28 00:21 drivers

-rw-r–r– 1 root root 425984 Apr 23 15:10 gencache.tdb

-rw——- 1 root root 696 Apr 23 15:10 group_mapping.tdb

drwxr-xr-x 1 root root 456 Apr 23 15:10 lock

drwxr-xr-x 1 root root 0 Apr 23 15:10 printing

drwx—— 1 root root 86 Apr 23 17:21 private

-rw——- 1 root root 528384 Apr 23 15:10 registry.tdb

-rw——- 1 root root 421888 Apr 23 15:10 share_info.tdb

-rw-r–r– 1 root root 483328 Apr 23 17:43 smbprofile.tdb

drwxr-x— 1 root wbpriv 0 Nov 28 00:21 winbindd_privileged

至于这些tdb文件如何查看数据,以及修改备份,下面介绍samba自带的几个tdb工具。

tdbtool工具介绍

tdbtool工具可以在命令行上接受命令,也可以打开交互式控制台类似shell一样。要在命令行上完成任务,请运行 tdbtool

example.tdb command options,其中 example.tdb 是文件名,command

是命令,针对命令的选项位于最后。要使用 tdb shell,只需单独运行 tdbtool

或在命令行上传递文件的名称。个人建议使用交互式控制台方式。以下是tdbtool参数介绍

tdbtool:

create dbname : create a database

open dbname : open an existing database

transaction_start : start a transaction

transaction_commit : commit a transaction

transaction_cancel : cancel a transaction

erase : erase the database

dump : dump the database as strings

keys : dump the database keys as strings

hexkeys : dump the database keys as hex values

info : print summary info about the database

insert key data : insert a record

move key file : move a record to a destination tdb

storehex key data : store a record (replace), key/value in hex format

store key data : store a record (replace)

show key : show a record by key

delete key : delete a record by key

list : print the database hash table and freelist

free : print the database freelist

freelist_size : print the number of records in the freelist

check : check the integrity of an opened database

repack : repack the database

speed : perform speed tests on the database

! command : execute system command

1 | first : print the first record

n | next : print the next record

q | quit : terminate

\n : repeat ‘next’ command

下面分别介绍:

1、创建数据库

【root@node1 tdbtest】# tdbtool

tdb> create hello

【root@node1 tdbtest】# ll

total 4

-rw——- 1 root root 696 Apr 23 15:53 hello

2、打开数据库

tdb> open hello

3、插入数据

tdb> insert name zhangsan

4、查询数据

tdb> show name

key 4 bytes

name

data 8 bytes

【000】 7A 68 61 6E 67 73 61 6E zhangsan

5、查看所有数据

tdb> dump

key 5 bytes

name1

data 4 bytes

【000】 6C 69 73 69 lisi

key 4 bytes

name

data 8 bytes

【000】 7A 68 61 6E 67 73 61 6E zhangsan

总共2条KEY/VALUES键值对,既2条数据信息。

6、列出key值

tdb> keys

key 5 bytes: name1

key 4 bytes: name

7、修改values值

tdb> store name zhang

Storing key:

key 4 bytes

name

data 5 bytes

【000】 7A 68 61 6E 67 zhang

将name值由zhangsan 修改为zhang,查看修改结果

tdb> dump

key 5 bytes

name1

data 4 bytes

【000】 77 61 6E 67 77 75 lisi

key 4 bytes

name

data 5 bytes

【000】 7A 68 61 6E 67 zhang

8、删除某个key值

tdb> delete name

tdb> dump

key 5 bytes

name1

data 4 bytes

【000】 6C 69 73 69 lisi

将key值为name的删掉后,查看只剩下name1记录。

9、检查数据完整性

tdb> check

Database integrity is OK and has 2 records.

10、复制数据到另外的数据库(后者数据库必须存在)

tdb> move name2 hello1

key 5 bytes

name2

data 6 bytes

【000】 77 61 6E 67 77 75 wangwu

record moved

查看hello1记录

tdb> open hello1

tdb> dump

key 5 bytes

name2

data 6 bytes

【000】 77 61 6E 67 77 75 wangwu

11、执行系统命令

tdb> ! pwd

/root/tdbtest

tdb> ! date

Mon Apr 23 16:36:18 CST 2018

12、支持事务处理

开启事务

tdb> transaction_start

tdb> insert name3 test

tdb> show name3

key 5 bytes

name3

data 4 bytes

【000】 74 65 73 74 test

取消事务

tdb> transaction_cancel

tdb> show name3

fetch failed

提交事务

tdb> transaction_start

tdb> insert name3 test

tdb> transaction_commit

tdb> show name3

key 5 bytes

name3

data 4 bytes

【000】 74 65 73 74 test

tdbdump 工具介绍

tdbdump是用来查看tdb文件中的所有键值对数据的工具

已hello为例, 查看所有数据

【root@node1 tdbtest】# tdbdump hello

{

key(5) = “name1”

data(4) = “lisi”

}

{

key(5) = “name2”

data(6) = “wangwu”

}

{

key(5) = “name3”

data(4) = “test”

}

每个键值对数据key data 数字为字节数

tdbbackup 工具介绍

tdbbackup工具为tdb数据库文件的备份工具。

– 备份hello数据库

【root@node1 tdbtest】# tdbbackup hello

【root@node1 tdbtest】# ll

total 828

-rw——- 1 root root 8//代码效果参考:http://www.zidongmutanji.com/bxxx/17784.html

31488 Apr 23 16:42 hello

-rw——- 1 root root 8192 Apr 23 16:38 hello1

-rw——- 1 root root 8192 Apr 23 17:25 hello.bak

hello.bak就是备份文件。这里发现两者文件大小不一样,通过md5对比。因为是不同的文件,文件MD5值肯定是不一样的,但是文件内容是完全一样的。

查看文件md5

【root@node1 tdbtest】# md5sum hello

8c55e7dabbeab30e3cd96e96b59fb052 hello

【root@node1 tdbtest】# md5sum hello.bak

c20b4f9b01f5715bbec8f950cf394f51 hello.bak

查看文件内容md5

【root@node1 tdbtest】# tdbdump hello | md5sum

88be32a888d3cd63132e09a0de8d69de –

【root@node1 tdbtest】# tdbdump hello.bak | md5sum

88be32a888d3cd63132e09a0de8d69de –

– 恢复hello数据

模拟删除数据

【root@node1 tdbtest】# ll

total 828

-rw——- 1 root root 831488 Apr 23 16:42 hello

-rw——- 1 root root 8192 Apr 23 16:38 hello1

-rw——- 1 root root 8192 Apr 23 17:25 hello.bak

【root@node1 tdbtest】# >hello

【root@node1 //代码效果参考:http://www.zidongmutanji.com/bxxx/174752.html

tdbtest】# ll

total 16

-rw——- 1 root root 0 Apr 23 17:33 hello

-rw——- 1 root root 8192 Apr 23 16:38 hello1

-rw——- 1 root root 8192 Apr 23 17:25 hello.bak

【root@node1 tdbtest】# tdbbackup -v hello

restoring hello

【root@node1 tdbtest】# ll

total 24

-rw——- 1 root root 8192 Apr 23 17:33 hello

-rw——- 1 root root 8192 Apr 23 16:38 hello1

-rw——- 1 root root 8192 Apr 23 17:25 hello.bak

看到文件大小一致了,现在对比md5值

【root@node1 tdbtest】# md5sum hello

c20b4f9b01f5715bbec8f950cf394f51 hello

【root@node1 tdbtest】# md5sum hello.bak

c20b4f9b01f5715bbec8f950cf394f51 hello.bak

【root@node1 tdbtest】# tdbdump hello |md5sum

88be32a888d3cd63132e09a0de8d69de –

【root@node1 tdbtest】# tdbdump hello.bak |md5sum

88be32a888d3cd63132//代码效果参考:http://www.zidongmutanji.com/bxxx/533118.html

e09a0de8d69de –

看到MD5值与之前备份之前一致了。查看数据

【root@node1 tdbtest】# tdbdump hello

{

key(5) = “name1”

data(4) = “lisi”

}

{

key(5) = “name2”

data(6) = “wangwu”

}

{

key(5) = “name3”

data(4) = “test”

}

相关文章
|
API 数据库 开发者
Python微服务框架:Flask与FastAPI的融合创新
在当今高度互联的世界中,构建可扩展、灵活和高效的微服务架构变得至关重要。Python作为一种广泛应用于Web开发的编程语言,其微服务框架Flask和FastAPI的概念与实践日益受到关注。本文将介绍这两个框架的核心概念,并探讨它们在实际应用中的强大功能和优势。
|
边缘计算 安全 中间件
软件体系结构 - 嵌入式系统(4)- 嵌入式中间件
软件体系结构 - 嵌入式系统(4)- 嵌入式中间件
970 0
|
关系型数据库 块存储
ceph 故障分析(backfill_toofull)
在执行了 ceph 扩容之前, 发现长时间内都具有下面的状态存在 参考下面信息 # ceph -s cluster dc4f91c1-8792-4948-b68f-2fcea75f53b9 health HEALTH_WARN 13 pgs backfill_toofull; 1 pgs degraded; 1 pgs stuck degraded
7662 0
|
8月前
|
Java 应用服务中间件 网络安全
SSL证书格式转换指南:PEM/PFX/JKS 核心指令实战
本文详解PEM、PFX、JKS三大证书格式的转换方法,涵盖OpenSSL与Keytool命令实操,强调私钥保护与证书链完整性,助力运维人员在Nginx、Tomcat等环境中安全高效完成部署,附常见问题与合规建议。
1631 6
|
Docker 容器
docker容器查看所有没使用的镜像,并删除
docker容器查看所有没使用的镜像,并删除
2124 0
|
存储 运维 监控
确定Ceph集群中OSD组件与具体物理磁盘的关联。
总结来说,确定Ceph集群中OSD与具体物理磁盘的关联需要搜集和对比Ceph集群的配置信息、OSD元数据、物理磁盘的详细信息,以及运行时的系统日志。这对于Ceph存储集群的维护和问题诊断至关重要,也有助于进行正常的运维活动,如扩容、升级或替换硬件。通过上述步骤,管理员可以直观且高效地管理和定位Ceph集群中的存储资源。
718 15
|
存储 负载均衡 NoSQL
搭建高可用及负载均衡的Redis
通过本文介绍的高可用及负载均衡Redis架构,可以有效提升Redis服务的可靠性和性能。主从复制、哨兵模式、Redis集群以及负载均衡技术的结合,使得Redis系统在应对高并发和数据一致性方面表现出色。这些配置和技术不仅适用于小型应用,也能够支持大规模企业级应用的需求。希望本文能够为您的Redis部署提供实用指导和参考。
1071 9
|
Kubernetes 数据库 容器
k8s快速部署xxl-job
k8s快速部署xxl-job
2383 3
|
存储 Linux C语言
C语言 多路复用 epoll
本文详细介绍了 Linux 下的非阻塞 IO 多路复用技术——`epoll`,对比 `select` 和 `poll`,`epoll` 使用红黑树结构存储文件描述符,支持动态增删节点,无数量限制,采用回调机制提高效率。文章通过示例代码展示了如何使用 `epoll_create()` 创建 `epoll` 实例,`epoll_ctl()` 管理文件描述符,以及 `epoll_wait()` 等待事件。最后简要分析了 `epoll` 的核心数据结构 `struct eventpoll` 和红黑树节点 `struct epitem`。
|
负载均衡 NoSQL 应用服务中间件
搭建高可用及负载均衡的Redis
【7月更文挑战第10天】
1026 1