rsync4j --I want to touch rsync in Java.

Thank you. It's funny. I want to use rsync for the development of a certain service. It's also in java. However, I couldn't find anything like rsync implemented in java.

While researching, I found the following

https://github.com/fracpete/rsync4j

Overview

This rsync4j is a rsync frontend that runs on windows and Linux. In windows, rsync is done by deploying the binary required for rsync once somewhere and executing it.

test

Works normally, yeah
Z:\users\desktop\a>ls
rsync4j-all-3.1.2-12-spring-boot.jar

Z:\users\desktop\a>java -jar rsync4j-all-3.1.2-12-spring-boot.jar
usage: com.github.fracpete.rsync4j.RSync
       [-h] [--output-commandline] [--maxtime MAXTIME] [-v]
       [--info INFO] [--debug DEBUG] [--msgs2stderr] [-q] [--no-motd] [-c]
       [-a] [-r] [-R] [--no-implied-dirs] [-b] [--backup-dir BACKUPDIR]
       [--suffix SUFFIX] [-u] [--inplace] [--append] [--append-verify] [-d]
       [-l] [-L] [--copy-unsafe-links] [--safe-links] [--munge-links] [-k]
       [-K] [-H] [-p] [-E] [--chmod CHMOD] [-X] [-o] [-g] [--devices]
       [--specials] [-t] [-O] [-J] [--super] [--fake-super] [-S]
       [--preallocate] [-n] [-W] [-x] [-B BLOCKSIZE] [-e RSH]
       [--rsync-path RSYNCPATH] [--existing] [--ignore-existing]
       [--remove-source-files] [--delete] [--delete-before]
       [--delete-during] [--delete-delay] [--delete-after]
       [--delete-excluded] [--ignore-missing-args] [--delete-missing-args]
       [--ignore-errors] [--force] [--max-delete MAXDELETE]
       [--max-size MAXSIZE] [--min-size MINSIZE] [--partial]
       [--partial-dir PARTIALDIR] [--delay-updates] [-m] [--numeric-ids]
       [--usermap USERMAP] [--groupmap GROUPMAP] [--chown CHOWN]
       [--timeout TIMEOUT] [--contimeout CONTIMEOUT] [-I] [-M REMOTEOPTION]
       [--size-only] [--modify-window MODIFYWINDOW] [-T TEMPDIR] [-y]
       [--compare-dest COMPAREDEST] [--copy-dest COPYDEST]
       [--link-dest LINKDEST] [-z] [--compress-level COMPRESSLEVEL]
       [--skip-compress SKIPCOMPRESS] [-C] [-f FILTER] [--exclude EXCLUDE]
       [--exclude-from EXCLUDEFROM] [--include INCLUDE]
       [--include-from INCLUDEFROM] [--files-from FILESFROM] [-0] [-s]
       [--address ADDRESS] [--port PORT] [--sockopts SOCKOPTS]
       [--blocking-io] [--stats] [-8] [--human-readable] [--progress] [-i]
       [--out-format OUTFORMAT] [--log-file LOGFILE]
       [--log-file-format LOGFILEFORMAT] [--password-file PASSWORDFILE]
       [--list-only] [--bwlimit BWLIMIT] [--outbuf OUTBUF]
       [--write-batch WRITEBATCH] [--only-write-batch ONLYWRITEBATCH]
       [--read-batch READBATCH] [--protocol PROTOCOL] [--iconv ICONV]
       [--checkum-seed CHECKSUMSEED] [-4] [-6] [--version]
       [--additional ADDITIONAL] src dest
com.github.fracpete.rsync4j.RSync: error: too few arguments

Z:\users\desktop\a>java -jar rsync4j-all-3.1.2-12-spring-boot.jar Z:\users\desktop\a Z:\users\desktop\a\a
9 16, 2018 9:59:32 pm com.github.fracpete.rsync4j.core.Binaries extractBinaries
information: Setting up rsync4j environment in 'C:\Users\hani\rsync4j'...
9 16, 2018 9:59:32 pm com.github.fracpete.rsync4j.core.Binaries extractBinaries
information: Creating directory: C:\Users\hani\rsync4j\bin
9 16, 2018 9:59:32 pm com.github.fracpete.rsync4j.core.Binaries extractBinaries
information: Creating directory: C:\Users\hani\rsync4j\home\hani\.ssh
9 16, 2018 9:59:32 pm com.github.fracpete.rsync4j.core.Binaries extractBinaries
information: Copy your public key pairs into: C:\Users\hani\rsync4j\home\hani\.ssh
9 16, 2018 9:59:32 pm com.github.fracpete.rsync4j.core.Binaries copyResourceTo
information: Copying resource 'com/github/fracpete/rsync4j/windows-x86_64/cygcom_err-2.dll' to 'C:\Users\hani\rsync4j\bin\cygcom_err-2.dll'
9 16, 2018 9:59:32 pm com.github.fracpete.rsync4j.core.Binaries copyResourceTo
information: Copying resource 'com/github/fracpete/rsync4j/windows-x86_64/cygcrypto-1.0.0.dll' to 'C:\Users\hani\rsync4j\bin\cygcrypto-1.0.0.dll'
9 16, 2018 9:59:32 pm com.github.fracpete.rsync4j.core.Binaries copyResourceTo
information: Copying resource 'com/github/fracpete/rsync4j/windows-x86_64/cyggcc_s-seh-1.dll' to 'C:\Users\hani\rsync4j\bin\cyggcc_s-seh-1.dll'
9 16, 2018 9:59:32 pm com.github.fracpete.rsync4j.core.Binaries copyResourceTo
information: Copying resource 'com/github/fracpete/rsync4j/windows-x86_64/cyggssapi_krb5-2.dll' to 'C:\Users\hani\rsync4j\bin\cyggssapi_krb5-2.dll'
9 16, 2018 9:59:32 pm com.github.fracpete.rsync4j.core.Binaries copyResourceTo
information: Copying resource 'com/github/fracpete/rsync4j/windows-x86_64/cygiconv-2.dll' to 'C:\Users\hani\rsync4j\bin\cygiconv-2.dll'
9 16, 2018 9:59:32 pm com.github.fracpete.rsync4j.core.Binaries copyResourceTo
information: Copying resource 'com/github/fracpete/rsync4j/windows-x86_64/cygintl-8.dll' to 'C:\Users\hani\rsync4j\bin\cygintl-8.dll'
9 16, 2018 9:59:32 pm com.github.fracpete.rsync4j.core.Binaries copyResourceTo
information: Copying resource 'com/github/fracpete/rsync4j/windows-x86_64/cygk5crypto-3.dll' to 'C:\Users\hani\rsync4j\bin\cygk5crypto-3.dll'
9 16, 2018 9:59:32 pm com.github.fracpete.rsync4j.core.Binaries copyResourceTo
information: Copying resource 'com/github/fracpete/rsync4j/windows-x86_64/cygkrb5-3.dll' to 'C:\Users\hani\rsync4j\bin\cygkrb5-3.dll'
9 16, 2018 9:59:32 pm com.github.fracpete.rsync4j.core.Binaries copyResourceTo
information: Copying resource 'com/github/fracpete/rsync4j/windows-x86_64/cygkrb5support-0.dll' to 'C:\Users\hani\rsync4j\bin\cygkrb5support-0.dll'
9 16, 2018 9:59:32 pm com.github.fracpete.rsync4j.core.Binaries copyResourceTo
information: Copying resource 'com/github/fracpete/rsync4j/windows-x86_64/cygwin1.dll' to 'C:\Users\hani\rsync4j\bin\cygwin1.dll'
9 16, 2018 9:59:32 pm com.github.fracpete.rsync4j.core.Binaries copyResourceTo
information: Copying resource 'com/github/fracpete/rsync4j/windows-x86_64/cygz.dll' to 'C:\Users\hani\rsync4j\bin\cygz.dll'
9 16, 2018 9:59:32 pm com.github.fracpete.rsync4j.core.Binaries copyResourceTo
information: Copying resource 'com/github/fracpete/rsync4j/windows-x86_64/ssh.exe' to 'C:\Users\hani\rsync4j\bin\ssh.exe'
9 16, 2018 9:59:32 pm com.github.fracpete.rsync4j.core.Binaries copyResourceTo
information: Copying resource 'com/github/fracpete/rsync4j/windows-x86_64/rsync.exe' to 'C:\Users\hani\rsync4j\bin\rsync.exe'
9 16, 2018 9:59:32 pm com.github.fracpete.rsync4j.core.Binaries copyResourceTo
information: Copying resource 'com/github/fracpete/rsync4j/windows-x86_64/ssh-keygen.exe' to 'C:\Users\hani\rsync4j\bin\ssh-keygen.exe'
skipping directory a

Z:\users\desktop\a>java -jar rsync4j-all-3.1.2-12-spring-boot.jar -av Z:\users\desktop\a Z:\users\desktop\a\a
sending incremental file list
a/
a/rsync4j-all-3.1.2-12-spring-boot.jar
a/a/

sent 9,556,407 bytes  received 47 bytes  19,112,908.00 bytes/sec
total size is 9,553,886  speedup is 1.00

Z:\users\desktop\a>

Call in Java.

Please write on maven like this.

<dependency>
    <groupId>com.github.fracpete</groupId>
    <artifactId>rsync4j-all</artifactId>
    <version>3.1.2-12</version>
</dependency>

Example: Neither is asynchronous.

Setting options


 // rsync -av /backupmoto/  /backupsaki/ --delete  --exclude='nozokitai/'
        RSync rsync = new RSync()
                .source("/backupmoto/")
                .destination("/backupsaki/")
                .archive(true).verbose(true).delete(true).exclude("nozokitai/");
        CollectingProcessOutput output = null;
        try {
            output = rsync.execute();
        } catch (Exception e) {
            e.printStackTrace();
        }
        System.out.println(output.getStdOut());
        System.out.println("Exit code: " + output.getExitCode());
        if (output.getExitCode() > 0)
            System.err.println(output.getStdErr());

        ////

Throw options in an array


        //rsync -av /backupmoto/  /backupsaki/ --delete  --exclude='nozokitai/'
        RSync rsync;
        try {
           rsync = new RSync();
           rsync.setOptions(new String[]{"-av", "/backupmoto/", "/backupsaki/", "--delete", "--exclude='nozokitai/"});
            CollectingProcessOutput output = rsync.execute();
            System.out.println(output.getStdOut());
            System.out.println("Exit code: " + output.getExitCode());
            if (output.getExitCode() > 0)
                System.err.println(output.getStdErr());
        } catch (Exception e) {
            e.printStackTrace();
        }

Summary

It would have been nice if it was implemented in java, but I wonder if it could be in the form of executing a binary. If I find out something in actual operation, I would like to give it back.

Ref https://fracpete.github.io/rsync4j/windows/ http://www.atmarkit.co.jp/ait/articles/1702/02/news031.html

Recommended Posts

rsync4j --I want to touch rsync in Java.
I want to send an email in Java.
I want to do something like "cls" in Java
I want to use ES2015 in Java too! → (´ ・ ω ・ `)
Even in Java, I want to output true with a == 1 && a == 2 && a == 3
I want to simplify the conditional if-else statement in Java
I want to stop Java updates altogether
I want to use @Autowired in Servlet
[Java] I want to perform distinct with the key in the object
Run R from Java I want to run rJava
I want to use arrow notation in Ruby
Even in Java, I want to output true with a == 1 && a == 2 && a == 3 (PowerMockito edition)
I tried to implement deep learning in Java
I want to use java8 forEach with index
I want to pass APP_HOME to logback in Gradle
(Limited to Java 7 or later) I want you to compare objects in Objects.equals
I wanted to make (a == 1 && a == 2 && a == 3) true in Java
I tried to output multiplication table in Java
[Xcode] I want to manage images in folders
I want to get the IP address when connecting to Wi-Fi in Java
I want to be eventually even in kotlin
I want to write quickly from java to sqlite
I want to ForEach an array with a Lambda expression in Java
I tried to create Alexa skill in Java
[Java Spring MVC] I want to use DI in my own class
I want to get the value in Ruby
Even in Java, I want to output true with a == 1 && a == 2 && a == 3 (Javassist second decoction)
Even in Java, I want to output true with a == 1 && a == 2 && a == 3 (black magic edition)
I want to use Combine in UIKit as well.
I want to use Clojure's convenient functions in Kotlin
[Java] I want to calculate the difference from the date
I want to embed any TraceId in the log
I tried to implement Firebase push notification in Java
I want to use fish shell in Laradock too! !!
# 2 [Note] I tried to calculate multiplication tables in Java.
I want to use a little icon in Rails
I tried to create a Clova skill in Java
I tried to make a login function in Java
I want to define a function in Rails Console
I want to transition screens with kotlin and java!
I want to stop snake case in table definition
When you want to dynamically replace Annotation in Java8
I want to click a GoogleMap pin in RSpec
I tried to implement the Euclidean algorithm in Java
~ I tried to learn functional programming in Java now ~
I want to get along with Map [Java beginner]
I tried to find out what changed in Java 9
I want to convert characters ...
I made roulette in Java.
I tried metaprogramming in Java
[Android Studio] I want to set restrictions on the values registered in EditText [Java]
I want to return an object in CSV format with multi-line header & filter in Java
# 1_JAVA I want to get the index number by specifying one character in the character string.
[Java] I want to convert a byte array to a hexadecimal number
I want to find a relative path in a situation using Path
I want to set the conditions to be displayed in collection_check_boxes
I want to build Java Applet without using an IDE
[Beginner] I made a program to sell cakes in Java
I want to perform high-speed prime factorization in Ruby (ABC177E)
I want to make a list with kotlin and java!
I just wanted to make a Reactive Property in Java