Sync
One-Way Directory or File Synchronization Tool. Free software written in Java.
Latest version: 2.1 (2007-12-09)
Simple command-line utility for one-way directory or file synchronization. Synchronize a specified target directory or file to match a specified source directory or file. Only the target is modified. Flexible file-matching: combinations of name, size, time, CRC. Flexible file time comparison: specify time-tolerance in milliseconds. Filename filters: specify multiple GLOB or REGEX filters. Simulation mode: useful for just comparing directories or files. Ideal for scripted or unattended usage. Free software written in Java.
Brief Description
Sync is a simple command-line utility for performing one-way directory or file synchronization. It synchronizes the specified target to match the specified source. Only the target is modified. Runs on any OS with the Java Runtime Environment (JRE 6+). Sync is free software written in Java and released under the GNU GPL license (version 3).
Main Features
- Flexible File-Matching: Match files by combinations of name, size, last-modified time, and CRC-32 checksum; by default, (name,size,time,crc) are used.
- Flexible File Time Comparison: Specify a time-tolerance (in milliseconds) when matching files by their last-modified time.
- Filename Filters: Use multiple GLOB or REGEX filters to include or exclude files based on their names or their relative pathnames.
- Simulation Mode: Sync can be run to simulate file operations, so that the target directory is not modified.
- Unattended Usage: With an appropriate choice of switches, Sync can be executed without user intervention.
- Log File: Sync can generate log files with automatic timestamps for convenient record-keeping.
Screenshots
Example of directory synchronization. |
System Requirements
A Java Runtime Environment (JRE 6+) is required. The latest version of the JRE can be downloaded from http://java.sun.com/j2se.
License
Sync is released with source code under the GNU General Public License (version 3).
Installation & Execution
The Sync utility is downloaded as a single Zip file with the following contents:
- Sync.jar – Sync executable JAR archive
- readme.txt – Release notes
- license.txt – License document (GNU GPLv3)
- unix/Sync – Unix/Linux script for executing Sync
- windows/Sync.bat – Windows batch file for executing Sync
- src/ – Source files
No installation is necessary — just unzip the downloaded file and you are ready to go. Assuming that the executable JAR archive Sync.jar is in the current directory, simply execute the following at the command-line:
java -jar Sync.jar
Several pages of documentation (usage syntax, notes, and examples) should fill the screen. The use of the Windows batch file (windows/Sync.bat) or the Unix/Linux script (unix/Sync) is recommended because it enables you to simply execute Sync
instead of java -jar Sync.jar
. Further instructions are given in the respective files.
Source Code
- src/sync/Sync.java
- src/sync/SyncIO.java
- src/sync/FileUnit.java
- src/sync/FileUnitComparator.java
- src/sync/FilterNode.java
- src/sync/FilePair.java
- src/sync/TerminatingException.java
Documentation
Usage Syntax
java -jar Sync.jar
<switches>
["Source"]
["Target"]
Synchronize ["Target"]
to match ["Source"]
. Only ["Target"]
is modified. By default, the filename, size, last-modified time, and CRC-32 checksum are used for file-matching. The synchronization mode depends on ["Source"]
:
-
["Source"]
is a DIRECTORY: Match source and target directories recursively. Matched target files are time-synced and renamed if necessary, unmatched source files are copied to the target directory, and unmatched target files/directories are deleted. -
["Source"]
is a FILE: Match source and target files, ignoring filename. If files match, then the target file is time-synced and renamed if necessary. If target file does not exist, then the source file is copied to the target.
<Switches>
−s , −−simulate |
Simulate only; do not modify target |
−−ignorewarnings |
Ignore warnings; do not pause |
−l , −−log:<x> |
Create log file x ; if x is not specified, "sync.yyyyMMdd-HHmmss.log" is used |
−r , −−norecurse |
Do not recurse into subdirectories |
−n , −−noname |
Do not use filename for file-matching |
−t , −−notime |
Do not use last-modified time for file-matching |
−c , −−nocrc |
Do not use CRC-32 checksum for file-matching |
−−time:[x] |
Use a x -millisecond time-tolerance for file-matching (0-millisecond time-tolerance is used by default; use −−time:1000 or more to avoid mismatches across different file systems) |
−−rename:[y|n] |
Always[y ]/never[n ] rename matched target files |
−−synctime:[y|n] |
Always[y ]/never[n ] synchronize time of matched target files |
−−overwrite:[y|n] |
Always[y ]/never[n ] overwrite existing target files/directories |
−−delete:[y|n] |
Always[y ]/never[n ] delete unmatched target files/directories |
−−force
| Equivalent to the combination: −−rename:y −−synctime:y −−overwrite:y −−delete:y |
A subset of source and/or target files/directories can be selected for synchronization using GLOB (or REGEX) filename filters. A file/directory is selected if it matches any of the "include" filters and none of the "exclude" filters.
−i , −−include:["x"] |
Include source and target files/directories with names matching GLOB expression x |
−x , −−exclude:["x"] |
Exclude source and target files/directories with names matching GLOB expression x |
−is , −−includesource:["x"] |
Include source files/directories with names matching GLOB expression x |
−xs , −−excludesource:["x"] |
Exclude source files/directories with names matching GLOB expression x |
−it , −−includetarget:["x"] |
Include target files/directories with names matching GLOB expression x |
−xt , −−excludetarget:["x"] |
Exclude target files/directories with names matching GLOB expression x |
−p , −−path |
Filter relative pathnames instead of filenames (e.g. "work\report\jan.txt" instead of "jan.txt") |
−w , −−lower |
Use lower case names for filtering (e.g. "HelloWorld2007.JPG" → "helloworld2007.jpg") |
−−regex |
Use REGEX instead of GLOB filename filters (see Java API for REGEX syntax) |
GLOB syntax:
* |
Match a string of 0 or more characters |
? |
Match exactly 1 character |
[ ] |
Match exactly 1 character inside the brackets:[abc] match a, b, or c[!abc] match any character except a, b, or c (negation)[a-z0-9] match any character a through z, or 0 through 9, inclusive (range) |
{ } |
Match exactly 1 comma-delimited string from inside the braces:{a,bc,def} match either a, bc, or def |
To use a construct symbol (e.g. [
, {
, ?
) as a literal character, insert a backslash before it, e.g. use \[
for the literal character [
. Use \\
for the literal backslash character \
.
The file separator in Windows can be specified by \\
or /
.
Examples
-
Synchronize target "C:\Backup" to look like source "C:\Original", matching files by (name,size,time,crc):
java -jar Sync.jar
"C:\Original"
"C:\Backup"
-
As in example 1, but never delete unmatched target files/directories:
java -jar Sync.jar
−−delete:n
"C:\Original"
"C:\Backup"
-
As in example 1, but match files by (name,size,time) with a time-tolerance of 2 seconds instead:
java -jar Sync.jar
−−nocrc −−time:2000
"C:\Original"
"C:\Backup"
-
As in example 1, but always rename and synchronize time of matched target files, overwrite existing target files, and delete unmatched target files/directories:
java -jar Sync.jar
−−force
"C:\Original"
"C:\Backup"
-
As in example 1, but synchronize only jpg and html files:
java -jar Sync.jar
−−include:"*.{jpg,html}"
"C:\Original"
"C:\Backup"
-
As in example 5, but skip files that begin with a tilde '~':
java -jar Sync.jar
−−include:"*.{jpg,html}"
−−exclude:"~*"
"C:\Original"
"C:\Backup"
Further Examples
-
Synchronize target "C:\Backup" to look like source "C:\Original", matching files by (name,size,time,crc):
java -jar Sync.jar
"C:\Original"
"C:\Backup"
-
As in example 1, but never delete unmatched target files/directories:
java -jar Sync.jar
−−delete:n
"C:\Original"
"C:\Backup"
-
As in example 1, but match files by (name,size,time) with a time-tolerance of 2 seconds instead:
java -jar Sync.jar
−−nocrc −−time:2000
"C:\Original"
"C:\Backup"
-
As in example 1, but always rename and synchronize time of matched target files, overwrite existing target files, and delete unmatched target files/directories:
java -jar Sync.jar
−−force
"C:\Original"
"C:\Backup"
-
As in example 1, but synchronize only jpg and html files:
java -jar Sync.jar
−−include:"*.{jpg,html}"
"C:\Original"
"C:\Backup"
-
As in example 5, but skip files that begin with a tilde '~':
java -jar Sync.jar
−−include:"*.{jpg,html}"
−−exclude:"~*"
"C:\Original"
"C:\Backup"
-
As in example 1, but skip "C:\Original\Temp1\*" and "C:\Original\Temp2\*":
java -jar Sync.jar
−−path
−−exclude:"{Temp1,Temp2}\\*"
"C:\Original"
"C:\Backup"
-
As in example 1, but skip any subfolder whose name is "Temp":
java -jar Sync.jar
−−path
−−exclude:"Temp\\*"
−−exclude:"*\\Temp\\*"
"C:\Original"
"C:\Backup"
-
As in example 1, but skip bmp and mp3 files, ignoring case:
java -jar Sync.jar
−−lower
−−exclude:"*.{bmp,mp3}"
"C:\Original"
"C:\Backup"
Feedback?
Comments, suggestions, and bug reports are welcomed! Please send any feedback you have about Sync to , or visit the Sync homepage at http://syncdir.sourceforge.net/ to post a message, bug report, or download the latest version of Sync.