mirror of
https://github.com/google/nomulus.git
synced 2025-07-21 02:06:00 +02:00
Implement compare_db_backups "main"
Implement toplevel class that reads in two database backups and displays diffs. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=168592124
This commit is contained in:
parent
51298aeabb
commit
07e5741cbb
6 changed files with 345 additions and 61 deletions
|
@ -13,6 +13,7 @@ package_group(
|
|||
"//java/google/registry/eclipse",
|
||||
"//java/google/registry/testing",
|
||||
"//java/google/registry/tools",
|
||||
"//javatests/google/registry/testing",
|
||||
"//javatests/google/registry/tools",
|
||||
],
|
||||
)
|
||||
|
@ -100,3 +101,18 @@ java_binary(
|
|||
"@com_google_appengine_remote_api//:link",
|
||||
],
|
||||
)
|
||||
|
||||
java_binary(
|
||||
name = "compare_db_backups",
|
||||
srcs = [
|
||||
"CompareDbBackups.java",
|
||||
],
|
||||
create_executable = 1,
|
||||
main_class = "google.registry.tools.CompareDbBackups",
|
||||
deps = [
|
||||
":tools",
|
||||
"@com_google_appengine_api_1_0_sdk",
|
||||
"@com_google_guava",
|
||||
"@com_google_protobuf_java",
|
||||
],
|
||||
)
|
||||
|
|
67
java/google/registry/tools/CompareDbBackups.java
Normal file
67
java/google/registry/tools/CompareDbBackups.java
Normal file
|
@ -0,0 +1,67 @@
|
|||
// Copyright 2017 The Nomulus Authors. All Rights Reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package google.registry.tools;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.Sets;
|
||||
import com.google.common.collect.Sets.SetView;
|
||||
import java.io.File;
|
||||
|
||||
/** Compare two database backups. */
|
||||
class CompareDbBackups {
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
if (args.length != 2) {
|
||||
System.err.println("Usage: compare_db_backups <directory1> <directory2>");
|
||||
return;
|
||||
}
|
||||
|
||||
ImmutableSet<ComparableEntity> entities1 =
|
||||
new RecordAccumulator().readDirectory(new File(args[0])).getComparableEntitySet();
|
||||
ImmutableSet<ComparableEntity> entities2 =
|
||||
new RecordAccumulator().readDirectory(new File(args[1])).getComparableEntitySet();
|
||||
|
||||
// Calculate the entities added and removed.
|
||||
SetView<ComparableEntity> added = Sets.difference(entities2, entities1);
|
||||
SetView<ComparableEntity> removed = Sets.difference(entities1, entities2);
|
||||
|
||||
printHeader(
|
||||
String.format("First backup: %d records", entities1.size()),
|
||||
String.format("Second backup: %d records", entities2.size()));
|
||||
|
||||
if (!removed.isEmpty()) {
|
||||
printHeader(removed.size() + " records were removed:");
|
||||
for (ComparableEntity entity : removed) {
|
||||
System.out.println(entity);
|
||||
}
|
||||
}
|
||||
|
||||
if (!added.isEmpty()) {
|
||||
printHeader(added.size() + " records were added:");
|
||||
for (ComparableEntity entity : added) {
|
||||
System.out.println(entity);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** Print out multi-line text in a pretty ASCII header frame. */
|
||||
private static void printHeader(String... headerLines) {
|
||||
System.out.println("========================================================================");
|
||||
for (String line : headerLines) {
|
||||
System.out.println("| " + line);
|
||||
}
|
||||
System.out.println("========================================================================");
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue