Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

zookeeper up to 3.4.9 #7

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
11 changes: 11 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
.project
.settings
/target
.checkstyle
.idea
*.iml
/vagrant/.vagrant
/vagrant/ansible
.classpath
/bin

2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
language: java
script: mvn clean verify
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<dependency>
<groupId>commons-cli</groupId>
<artifactId>commons-cli</artifactId>
<version>1.2</version>
<version>1.3.1</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
Expand All @@ -23,7 +23,7 @@
<dependency>
<groupId>org.apache.zookeeper</groupId>
<artifactId>zookeeper</artifactId>
<version>3.4.3</version>
<version>3.4.9</version>
<exclusions>
<exclusion>
<groupId>com.sun.jmx</groupId>
Expand Down
32 changes: 29 additions & 3 deletions readme.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,25 @@
usage: guano
BADGES

[ ![Download](https://api.bintray.com/packages/feldoh/Guano/guano/images/download.svg) ](https://bintray.com/feldoh/Guano/guano/_latestVersion) [![Build Status](https://travis-ci.org/feldoh/guano.svg?branch=master)](https://travis-ci.org/feldoh/guano)

-s,--server <arg> the zookeeper remote server to connect to (ie
"localhost:2181"
NAME

guano -- dump or restore Zookeeper trees

SYNOPSIS

guano [operands ...]

DESCRIPTION

This tool dumps and restores zookeeper state to/from a matching folder structure on disk.
The server argument is mandatory then either a node to dump and where to dump it,
or a previous dump to restore and the root to restore it to.

usage: guano [-v] -s <zk_connect> [-d <znode> -o <folder>] [-r <znode-root> -i <folder>]

-s,--server <arg> *Required, the zookeeper remote server to connect to
i.e. "localhost:2181"

-d,--dump-znode <arg> the znode to dump (recursively)
-o,--output-dir <arg> the output directory to which znode
Expand All @@ -14,3 +32,11 @@
restored

-v,--verbose enable debug output

Note: When restoring you need to provide one level up as the node selected for the dump is included.
e.g. java -jar target/guano-0.1a.jar -s "zookeeper-01.mydomain.com" -o "/tmp/zkdump" -d "/myroot"
java -jar target/guano-0.1a.jar -s "zookeeper-01.mydomain.com" -i "/tmp/zkdump" -r "/"

PREBUILT BINARIES

Pre-built binaries are available for most common platforms on Bintray
24 changes: 21 additions & 3 deletions src/main/java/com/d2fn/guano/DumpJob.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package com.d2fn.guano;

import org.apache.zookeeper.KeeperException;
import org.apache.zookeeper.WatchedEvent;
import org.apache.zookeeper.Watcher;
import org.apache.zookeeper.ZooKeeper;
import org.apache.zookeeper.data.Stat;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.List;

/**
Expand Down Expand Up @@ -62,8 +64,7 @@ private void dumpChild(ZooKeeper zk, String outputPath, String znodeParent, Stri
if(!children.isEmpty()) {

// ensure parent dir is created
File f = new File(outputPath);
boolean s = f.mkdirs();
createFolder(outputPath);

// this znode is a dir, so ensure the directory is created and build a __znode value in its dir
writeZnode(zk, outputPath + "/_znode", currznode);
Expand All @@ -90,9 +91,26 @@ private void writeZnode(ZooKeeper zk, String outFile, String znode) throws Excep
out.flush();
out.close();
}
} else {
if (!outFile.contains("_znode") && stat.getEphemeralOwner() == 0) {
// Create an empty folder for Permanent nodes.
createFolder(outFile);
}

}
}

private void createFolder(String path) {
File f = new File(path);
if(!f.exists() ) {
boolean s = f.mkdirs();
if (s) {
System.out.println("Created folder: " + path);
}
}

}

@Override
public void process(WatchedEvent watchedEvent) {
;;
Expand Down