因为我在亚马逊上遇到很多管道问题我决定用java来备份我的数据库。我的桌子是50GB然后我需要最好的方法来保存它。 这是读取元素并将其写入文件的java代码:
public static void fetchItems() {
try{
FileWriter file=new FileWriter(path);
ScanResult result = null;
long sum=0;
do{
ScanRequest req = new ScanRequest();
req.setTableName(dataTable);
if(result != null){
req.setExclusiveStartKey(result.getLastEvaluatedKey());
}
result = dynamoDB.scan(req);
List<Map<String, AttributeValue>> rows = result.getItems();
for(Map<String, AttributeValue> map : rows){
try{
JSONObject json=new JSONObject(map);
file.write(json.toString());
} catch (NumberFormatException e){
System.out.println(e.getMessage());
} catch (IOException e) {
System.out.println(e.getMessage());
}
}
sum+= result.getItems().size();
System.out.println("Result size: " + sum);
} while(result.getLastEvaluatedKey() != null);
file.flush();
file.close();
}catch(IOException e){
System.out.println(e.getMessage());
文件的扩展名以及如何保存数据? 使用我的代码文件太大而且很多字段都是null(新JSONObject(map)的问题),有人有想法吗? 在我找到的文件中写道:
{&#34; leaseOwner&#34; {&#34; SS&#34;:空,&#34; BS&#34;:空,&#34; B&#34;:空,&#34 ; S&#34;:&#34; IP-120-115-91-22346.eu-西1.compute.internal:ef5c43f7-f5b7-49cf-99e6-8601db2922e2&#34;&#34; N&#34 ;:空,&#34; L&#34;:空,&#34; NS&#34;:空,&#34; M&#34;:空,&#34; NULL&#34;:空,&# 34; BOOL&#34;:空}&#34; leaseKey&#34; {&#34; SS&#34;:空,&#34; BS&#34;:空,&#34; b&#34; :空,&#34; S&#34;:&#34; shardId-000000000002&#34;&#34; N&#34;:空,&#34; L&#34;:空,&#34; NS& #34;:空,&#34; M&#34;:空,&#34; NULL&#34;:空,&#34; BOOL&#34;:空}&#34; ownerSwitchesSinceCheckpoint&#34;:{ &#34; SS&#34;:空,&#34; BS&#34;:空,&#34; b&#34;:空,&#34; S&#34;:空,&#34; N&# 34;:&#34; 0&#34;&#34; L&#34;:空,&#34; NS&#34;:空,&#34; M&#34;:空,&#34; NULL& #34;:空,&#34; BOOL&#34;:空}&#34;检查点&#34; {&#34; SS&#34;:空,&#34; BS&#34;:空, &#34; b&#34;:空,&#34; S&#34;:&#34; 49551567310479336289724454124452290401607015400753594402&#34;&#34; N&#34;:空,&#34; L&#34;:空&#34; NS&#34;:空,&#34; M&#34;:空,&#34; NULL&#34;:空,&#34; BOOL &#34;:空}&#34; leaseCounter&#34; {&#34; SS&#34;:空,&#34; BS&#34;:空,&#34; B&#34;:空&#34; S&#34;:空,&#34; N&#34;:&#34; 34905&#34;&#34; L&#34;:空,&#34; NS&#34 ;:空,&#34; M&#34;:空,&#34; NULL&#34;:空,&#34; BOOL&#34;:空}} {&#34; leaseOwner&#34; {&#34 ; SS&#34;:空,&#34; BS&#34;:空,&#34; b&#34;:空,&#34; S&#34;:&#34; IP-120-115-91 -22346.eu-西1.compute.internal:ef5c43f7-f5b7-49cf-99e6-8601db2922e2&#34;&#34; N&#34;:空,&#34; L&#34;:空,&# 34; NS&#34;:空,&#34; M&#34;:空,&#34; NULL&#34;:空,&#34; BOOL&#34;:空}&#34; leaseKey&#34 ;:{&#34; SS&#34;:空,&#34; BS&#34;:空,&#34; b&#34;:空,&#34; S&#34;:&#34; shardId -000000000000&#34;&#34; N&#34;:空,&#34; L&#34;:空,&#34; NS&#34;:空,&#34; M&#34;:空, &#34; NULL&#34;:空,&#34; BOOL&#34;:空}&#34; ownerSwitchesSinceCheckpoint&#34; {&#34; SS&#34;:空,&#34; BS&# 34;:空,&#34; b&#34;:空,&#34; S&#34;:空,&#34; N&#34;:&#34; 0&#34;&#34; L& #34;:空,&#34; NS&#34;:空,&#34; M&#34;:空,&#34; NULL&#34;:空,&#34; BOOL&#34;:空} &#34;检查点&#34; {&#34; S S&#34;:空,&#34; BS&#34;:空,&#34; B&#34;:空,&#34; S&#34;:&#34; 49551567310434734799327392878132951190473279252744634370&#34;&#34 ; N&#34;:空,&#34; L&#34;:空,&#34; NS&#34;:空,&#34; M&#34;:空,&#34; NULL&#34 ;:空,&#34; BOOL&#34;:空}&#34; leaseCounter&#34; {&#34; SS&#34;:空,&#34; BS&#34;:空,&#34; b&#34;:空,&#34; S&#34;:空,&#34; N&#34;:&#34; 34913&#34;&#34; L&#34;:空,&#34 ; NS&#34;:空,&#34; M&#34;:空,&#34; NULL&#34;:空,&#34; BOOL&#34;:空}} {&#34; leaseOwner&#34 ;:{&#34; SS&#34;:空,&#34; BS&#34;:空,&#34; b&#34;:空,&#34; S&#34;:&#34; IP -120-115-91-22346.eu-西1.compute.internal:ef5c43f7-f5b7-49cf-99e6-8601db2922e2&#34;&#34; N&#34;:空,&#34; L&#34 ;:空,&#34; NS&#34;:空,&#34; M&#34;:空,&#34; NULL&#34;:空,&#34; BOOL&#34;:空},& #34; leaseKey&#34; {&#34; SS&#34;:空,&#34; BS&#34;:空,&#34; b&#34;:空,&#34; S&#34; :&#34; shardId-000000000001&#34;&#34; N&#34;:空,&#34; L&#34;:空,&#34; NS&#34;:空,&#34; M& #34;:空,&#34; NULL&#34;:空,&#34; BOOL&#34;:空}&#34; ownerSwitchesSinceCheckpoi NT&#34; {&#34; SS&#34;:空,&#34; BS&#34;:空,&#34; B&#34;:空,&#34; S&#34;:空, &#34; N&#34;:&#34; 0&#34;&#34; L&#34;:空,&#34; NS&#34;:空,&#34; M&#34;:空&#34; NULL&#34;:空,&#34; BOOL&#34;:空}&#34;检查点&#34; {&#34; SS&#34;:空,&#34; BS& #34;:空,&#34; b&#34;:空,&#34; S&#34;:&#34; 49551567310457035544525923501292620796040147120590684178&#34;&#34; N&#34;:空,&#34;升&#34;:空,&#34; NS&#34;:空,&#34; M&#34;:空,&#34; NULL&#34;:空,&#34; BOOL&#34;:空},&#34; leaseCounter&#34; {&#34; SS&#34;:空,&#34; BS&#34;:空,&#34; b&#34;:空,&#34; S& #34;:空,&#34; N&#34;:&#34; 34912&#34;&#34; L&#34;:空,&#34; NS&#34;:空,&#34;米&#34;:空,&#34; NULL&#34;:空,&#34; BOOL&#34;:空}}
之后我还要实现还原应用程序。 谢谢
答案 0 :(得分:0)
我用csv格式做了这个,看起来最简洁。第一行应该包含字段名称(有点像excel标题),因此它们不会重复每一行,而stil启用解析文件。空值只是相邻的逗号。