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 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
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 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
88be32a888d3cd63132e09a0de8d69de –
看到MD5值与之前备份之前一致了。查看数据
[root@node1 tdbtest]# tdbdump hello
{
key(5) = “name1”
data(4) = “lisi”
}
{
key(5) = “name2”
data(6) = “wangwu”
}
{
key(5) = “name3”
data(4) = “test”
}
TDB文件介绍的更多相关文章
- Linux core 文件介绍
Linux core 文件介绍 http://www.cnblogs.com/dongzhiquan/archive/2012/01/20/2328355.html 1. core文件的简单介绍在一个 ...
- linux设备驱动程序该添加哪些头文件以及驱动常用头文件介绍(转)
原文链接:http://blog.chinaunix.net/uid-22609852-id-3506475.html 驱动常用头文件介绍 #include <linux/***.h> 是 ...
- Android下HelloWorld项目的R.java文件介绍
R.java文件介绍 HelloWorld工程中的R.java文件 package com.android.hellworld; public final class R { public s ...
- APK扩展文件介绍、功能及用法
APK扩展文件介绍 Android Market (Google Play Store)中每一个APK文件的最大限制是50MB.假设您的程序中包括大量的数据文件,曾经您仅仅能把这些数据文件放到自己的s ...
- NSIS文字及字符串函数与头文件介绍
原文 NSIS文字及字符串函数与头文件介绍 文字函数,顾名思义就是处理字符串的函数.使用这些字符串函数前,必须先包含头文件WordFunc.nsh.该头文件目前包含如下一些函数:WordFind.Wo ...
- opensslBIO系列之2---BIO结构和BIO相关文件介绍
BIO结构和BIO相关文件介绍 (作者:DragonKing Mail:wzhah@263.net 公布于:http://gdwzh.126.com openssl专业论坛) ...
- 微信小程序-01-项目组成文件介绍(入门篇)
自古开篇先说两句,写这些笔记不是学习用的,主要是后续分享一些遇到的坑,碰到过什么样的问题,怎么去解决,如果你不是一个很耐心无看文章的人,建议去 网易云课堂找一些课程,跟着别人的脚步或许会更有动力,我的 ...
- IOS-项目中常见文件介绍
一.项目文件结构示意图 二.文件介绍 1.products文件夹:主要用于mac电脑开发的可执行文件,ios开发用不到这个文件 2.frameworks文件夹主要用来放依赖的框架 3.test文件夹是 ...
- Linux文件介绍
Linux文件介绍 Linux 文件属性 可以通过命令ll+文件名,查看文件的具体属性 例如:ll syz.gz 1736706 -rw-r--r--. 1 root root 28 Oct 27 1 ...
随机推荐
- openinstall的免费服务对App推广有哪些帮助?
想在微信中下载 App,需要“点击右上角打开浏览器”,太麻烦: 想深入查看微信分享内容,需要手动打开 App 搜索,不方便: 想给 App 做推广,Android 需要多个渠道人工打包,效率低: .. ...
- Mac 下sublime的插件
最近更换了本本,入了港行的Mac pro,来替代原来的Thinkpad,在windows上工作做完之后,搭建了一下开发环境,eclipse是必须的,但是luna没有html editor,然后就在 e ...
- nginx反向代理解决跨域问题,使本地调试更方便
我们可能都会遇到一个这样的问题,线上环境是https://...,本地启动了项目,域名是localhost:8000等,本地想要访问线上的接口,直接在本地调试,却提示跨域,这个时候我们可以配置ngin ...
- Java-GC-标记压缩算法
标记压缩算法 其分为两个阶段标记阶段,和压缩阶段.其中标记阶段和标记清除算法的标记阶段是一样的. 对压缩算法来说,他的工作就是移动所有的可达对象到堆内存的同一区域中,使它们紧凑的排列在一起,从而将所有 ...
- C 语言实例 - 求两数最小公倍数
C 语言实例 - 求两数最小公倍数 用户输入两个数,其这两个数的最小公倍数. 实例 - 使用 while 和 if #include <stdio.h> int main() { int ...
- 查看java 版本
执行 java -version 命令,如下图所示如果没有明确显示位数的,则说明是32位 C:\MyTools\jdk1.7.0\bin>java -version java version & ...
- Js $.merge() 函数(合并两个数组内容到第一个数组)
定义和用法 $.merge() 函数用于合并两个数组内容到第一个数组. 语法 $.merge( first, second ) 参数 描述 first Array类型 第一个用于合并的数组,合并后 ...
- 【ZROI 537】贪心题 题解
[ZROI 537]贪心题 题解 Link Solution 最大的一边直接放到一起贪心即可 着重讲小的一边 已知对于二分图匹配,其答案即为最大流 令时间集合为 \(T = {1,2,3,\dots, ...
- 【poj3764】The xor-longest Path
The xor-longest Path Description In an edge-weighted tree, the xor-length of a path p is defined as ...
- net Core 入门实战
Asp.net Core 入门实战 Asp.Net Core 是开源,跨平台,模块化,快速而简单的Web框架. Asp.net Core官网的一个源码合集,方便一次性Clone 目录 快速入门 安 ...