aerospik工具集——备份和还原

asbackup备份命令的使用
asbackup备份命令的运行方式:
asbackup [OPTIONS]
命令的最简单形式是指定需要备份的命名空间( namespace )和本地目录。
例子:
asbackup -d backup_01_23_2013 -n test

其中-d为导出需要保存的文件,-n为需要导出的namespace

如何在指定的群集上备份命名空间(namespace):
  • 高优先级 -f 3,
  • 如果集群失败了(即你希望数据是正确的),终止备份 -c
  • 提供详细的信息到控制台-v
例子:
asbackup -h 10.0.0.9 -p 3000-d backup_01_23_2013 -n test -f3 -c -v
或者如果你想备份集群的特定节点,只需要给它地址和服务端口(默认3000)的节点。
$ asbackup -l"host1:port1;host2:port2"-d backup_01_23_2013 -n test -f3 -c -v

命令参数各选项说明:
Option Default Description
-h host 127.0.0.1 Host that acts as seed (entry point) to the cluster. Any single node can be specified and the entire cluster will be automatically discovered.
-p port 3000 Port to use with the host specified in the -h option.
-n namespace - Namespace to back up. (Mandatory)
-s set ALL SETS The SET to backup up.
-U user name - User name with read permission. (Mandatory if security is enabled on server side)
-P password - Password.
-d directory - Local directory where the backup .asb files will be stored. If the directory does not exist, it will be created before use. (Mandatory)
-F file size 1GB 文件大小。在跨越这个限制之后,将创建新文件。
-r False Clean up directory - If this option is specified, then any .asb files in the backup directory will be removed before the backup begins. 
If this option is not specified and .asb files are found in the directory, the backup will terminate and you need to remove the files manually or change directory.
-f scan priority 2 Scan priority - This option controls the level of concurrency on a node. Increasing this setting will increase the speed of the backup, but should be done while monitoring normal read/write performance to make sure cluster performance is not affected
The allowed values are: 
  • 1=low (1 thread)低优先级
  • 2=med (3 threads)中等优先级
  • 3=high (5 threads)高优先级
-c False Terminate on cluster change or ongoing migrations - If this option is specified the backup will fail if the cluster changes. 
When a cluster changes (for example, a node goes down), there is a period of time where the data migrates between the nodes to rebalance the cluster. If a backup is running while data rebalances, it is possible to get the same object backed up twice, or have some data that may be missed. 
To get a good, complete backup, use this option so that asbackup will fail if the cluster changes during the backup.
-v False Verbose mode - Use this option to enable verbose mode so that additional messages are displayed on the console.
-B bin_list All bins Backup with specific bins.
-x False "No bin" mode - While enabled the backup does not store data – i.e., Backup of only metadata is taken. 
When this option is set ONLY THE RECORD METADATA (digest information, the TTL and the generation information) is backed up.
(Note that this is different from the single-bin option in the configuration file.)
-w number of nodes 10 Number of nodes to back up in parallel. Backup will concurrently query the requested number of nodes. As backup for each node completes, an additional node will be added to the nodes being backed up. 
Setting this number too high may result in the client getting overloaded.
-l list of nodes ALL List of nodes to back up. This option allows you to specify which nodes to backup up. 
The list is of the form: 
node1 : port1 ; node2 : port2 ; ... ; noden : portn 
When you specify this option, the -h and -p options are ignored and the first host/port in the list is used to connect to the cluster.
-% scan percentage 100% Percentage of each partition to backup. This option is useful for sampling – for example, you might backup 10% of the data to analyze with a script.
-b False Store all strings as Special Strings with base64 encoding. If this option is specified, strings will be converted to base64 encoding and included in the backup as X TYPE Strings .
Reason for this is if your strings contain non-printable characters, those characters may cause formatting errors in the backup files that prevent asrestore from correctly restoring the data unless you use the -b option. From tools version 3.3.24 this option is no-op(depricated) and By default all strings will be stored as base64 encoded string
-S False From tools version 3.3.26 use this option to store normal strings as string only instead of base64 encoded
--usage - Display command usage.

运行例子
[root@mobiead-06 server]# asbackup -d backup_01_23_2013 -n test
Backing up From: host 127.0.0.1 port 3000 namespace test set  bin_list (null) to directory backup_01_23_2013 with scan_pct 100 
2015-08-26 13:32:32 INFO Add node BB9D72500FA1700 127.0.0.1:3000
Aerospike scan nodes: 1 nodes 
Node_name         Objects         Rep_fact  
BB9D72500FA1700   1698618         1
could not open directory. creating backup_01_23_2013
directory "backup_01_23_2013" prepared for backup
starting backup for node BB9D72500FA1700 
Aug 26 2015 05:32:32 GMT: New file created backup_01_23_2013/BB9D72500FA1700_00000.asb
Aug 26 2015 05:32:33 GMT: backed up records 5%
Aug 26 2015 05:32:34 GMT: backed up records 10%
Aug 26 2015 05:32:34 GMT: New file created backup_01_23_2013/BB9D72500FA1700_00001.asb
Aug 26 2015 05:32:35 GMT: backed up records 16%
Aug 26 2015 05:32:36 GMT: backed up records 22%
Aug 26 2015 05:32:36 GMT: New file created backup_01_23_2013/BB9D72500FA1700_00002.asb
Aug 26 2015 05:32:37 GMT: backed up records 27%
Aug 26 2015 05:32:38 GMT: backed up records 32%
Aug 26 2015 05:32:38 GMT: New file created backup_01_23_2013/BB9D72500FA1700_00003.asb
Aug 26 2015 05:32:39 GMT: backed up records 38%
Aug 26 2015 05:32:40 GMT: backed up records 44%
Aug 26 2015 05:32:40 GMT: New file created backup_01_23_2013/BB9D72500FA1700_00004.asb
Aug 26 2015 05:32:41 GMT: backed up records 49%
Aug 26 2015 05:32:42 GMT: backed up records 55%
Aug 26 2015 05:32:42 GMT: New file created backup_01_23_2013/BB9D72500FA1700_00005.asb
Aug 26 2015 05:32:43 GMT: backed up records 60%
Aug 26 2015 05:32:44 GMT: backed up records 66%
Aug 26 2015 05:32:44 GMT: New file created backup_01_23_2013/BB9D72500FA1700_00006.asb
Aug 26 2015 05:32:45 GMT: backed up records 71%
Aug 26 2015 05:32:46 GMT: backed up records 77%
Aug 26 2015 05:32:47 GMT: New file created backup_01_23_2013/BB9D72500FA1700_00007.asb
Aug 26 2015 05:32:47 GMT: backed up records 83%
Aug 26 2015 05:32:48 GMT: backed up records 88%
Aug 26 2015 05:32:49 GMT: backed up records 94%
Aug 26 2015 05:32:49 GMT: New file created backup_01_23_2013/BB9D72500FA1700_00008.asb
Aug 26 2015 05:32:50 GMT: backed up records 99%
Complete backup for node BB9D72500FA1700 and total backed up from this node: 1698618

Aug 26 2015 05:32:51 GMT: backed up records 100%
Aug 26 2015 05:32:51 GMT: Backup successfully completed.
Aug 26 2015 05:32:51 GMT: Total backed up records from all nodes 1698618



asrestore备份命令的使用
asrestore备份命令的运行方式:
asrestore [OPTIONS]
例如:需要从先前的备份中恢复所有的数据,你可以使用如下的命令:
$ asrestore -h 127.0.0.1 -p 3000-d /home/aerospike/backup_10_23_2011
-d为之前备份的数据文件目录;


命令参数各选项说明:
Option Default Description
-d <target> [None] Path to the directory where the backup files are located. (Mandatory)
-h <host> 127.0.0.1 Host that acts as seed (entry point) to the cluster where data needs to be restored. Any single node can be specified and the entire cluster will be automatically discovered.
-p <port> 3000 Port to use with the host specified in the -h option.
-U user name - User name with read permission. (Mandatory if security is enabled on server side)
-P password - Password.
-B bin_list All bins Restore only specific bins.
`-b batch size 100 可批量插入元素。最大允许为100。
-r replace or create update or create 更换或创建记录。
-t <threads> 20 在本地机器上运行备份的线程数。线程数的增加会使恢复过程更快,但设置值过高会使本地机器超载。
-u DISABLED 丢失的记录。当这个选项被指定时,只在所有群集中不存在的记录被插入。 如果群集上存在这记录, 然后,该记录的备份版本将被丢弃,不管生成数(generation number)。 如果记录包含LDT bins,则不使用此选项。
-g DISABLED 忽略generation number. When this option is set, records in the backup set overwrite records that already exist in the database, even if the generation number of the record in the database is newer. If record contains LDT bins dont use this option.
By using this option you may loose most recent copy of your data
-v DISABLED 详细模式-如果指定了该选项,详细模式的启用和更多的信息显示在控制台。
--usage [None] Display command usage.

如果你想改变的目标命名空间(namespace)或设置哪些数据需要恢复,详情请联系aerospike的支持。

运行例子:
$ asrestore -d /home/john/dir
restoring: host 127.0.0.1 port 3000 from directory /home/john/dir
Sep 04201323:48:04 GMT: starting restore: filename: /home/john/dir/BB925F305CA0568_00000.asb FILE 0x7f65a80008c0
Sep 04201323:48:04 GMT: starting restore: filename: /home/john/dir/BB939F706CA0568_00000.asb FILE 0x7f65a00008c0

Sep 04201323:48:04 GMT: restore complete /home/john/dir/BB925F305CA0568_00000.asb processed 17 items
Sep 04201323:48:04 GMT: restore complete /home/john/dir/BB939F706CA0568_00000.asb processed 24 items
Sep 04201323:48:05 GMT: expired 0 : attempted 41 : [updated 41 not-updated (existed 0 gen-old 0)]

执行中的输出日志:
Sep 3201312:57:15 GMT: expired 4333 : attempted 3563832 : [updated 1354433 not-updated (existed 0 gen-old 2100432)]
4333个记录被忽略,因为他们过期了;
3563832个试图写入群集记录
试图写的,
1354433成功更新,
2100432没有更新成功,因为版本(generation )不匹配。(即,该服务器已具有相同或更晚版本的记录)。



备份文件的格式
作为asbackup的备份文件,ASB文件是可读的。

文件格式
该文件包括:
Version VERSION
( RECORD )
( RECORD )
...
VERSION:备份文件格式的版本号
RECORD:从数据库中备份每一条记录

Record Entry

+ k TYPE TYPE-SPECIFIC
+ n NAMESPACE
+ d DIGEST
+ s SET
+ g GENERATION
+ t TTL
+ b NBINS
- ( BIN )
- ( BIN )
...

TYPE-SPECIFIC:String,Special String,Integer,Blob,
Special  Blob,List,Map,LargeList

详情可以查看官方文档: http://www.aerospike.com/docs/tools/backup/file_format.html







你可能感兴趣的:(aerospik工具集——备份和还原)