org.jets3t.apps.synchronize
Class Synchronize

java.lang.Object
  extended by org.jets3t.apps.synchronize.Synchronize

public class Synchronize
extends java.lang.Object

Console application to synchronize the local file system with Amazon S3. For more information and help please see the Synchronize Guide.

Author:
James Murty

Field Summary
static java.lang.String APPLICATION_DESCRIPTION
           
protected static int REPORT_LEVEL_ACTIONS
           
protected static int REPORT_LEVEL_ALL
           
protected static int REPORT_LEVEL_DIFFERENCES
           
protected static int REPORT_LEVEL_NONE
           
 
Constructor Summary
Synchronize(S3Service s3Service, boolean doAction, boolean isQuiet, boolean isNoProgress, boolean isForce, boolean isKeepFiles, boolean isNoDelete, boolean isMoveEnabled, boolean isBatchMode, boolean isSkipMetadata, boolean isGzipEnabled, boolean isEncryptionEnabled, int reportLevel, Jets3tProperties properties)
          Constructs the application with a pre-initialised S3Service and the user-specified options.
 
Method Summary
static void main(java.lang.String[] args)
          Runs this application from the console, accepts and checks command-line parameters and runs an upload or download operation when all the necessary parameters are provided.
 void restoreFromS3ToLocalDirectory(java.util.Map filesMap, java.lang.String rootObjectPath, java.io.File localDirectory, S3Bucket bucket, BytesProgressWatcher progressWatcher)
          Copies the contents of a root path in S3 to the local file system.
 void run(java.lang.String s3Path, java.util.List fileList, java.lang.String actionCommand, java.lang.String cryptoPassword, java.lang.String aclString)
          Runs the application, performing the action specified on the given S3 and local directory paths.
 void uploadLocalDirectoryToS3(java.util.Map filesMap, S3Bucket bucket, java.lang.String rootObjectPath, java.lang.String aclString, BytesProgressWatcher progressWatcher)
          Copies the contents of a local directory to S3, storing them in the given root path.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

APPLICATION_DESCRIPTION

public static final java.lang.String APPLICATION_DESCRIPTION
See Also:
Constant Field Values

REPORT_LEVEL_NONE

protected static final int REPORT_LEVEL_NONE
See Also:
Constant Field Values

REPORT_LEVEL_ACTIONS

protected static final int REPORT_LEVEL_ACTIONS
See Also:
Constant Field Values

REPORT_LEVEL_DIFFERENCES

protected static final int REPORT_LEVEL_DIFFERENCES
See Also:
Constant Field Values

REPORT_LEVEL_ALL

protected static final int REPORT_LEVEL_ALL
See Also:
Constant Field Values
Constructor Detail

Synchronize

public Synchronize(S3Service s3Service,
                   boolean doAction,
                   boolean isQuiet,
                   boolean isNoProgress,
                   boolean isForce,
                   boolean isKeepFiles,
                   boolean isNoDelete,
                   boolean isMoveEnabled,
                   boolean isBatchMode,
                   boolean isSkipMetadata,
                   boolean isGzipEnabled,
                   boolean isEncryptionEnabled,
                   int reportLevel,
                   Jets3tProperties properties)
Constructs the application with a pre-initialised S3Service and the user-specified options.

Parameters:
s3Service - a pre-initialised S3Service (including AWS Authorization credentials)
doAction - Files will only be transferred if true.
isQuiet - Report will only include summary of actions if true.
isForce - Files will be overwritten when unchanged if true.
isKeepFiles - Files will not be replaced/deleted if true.
isMoveEnabled - If true, items will be moved rather than just copied. Files will be deleted after they have been uploaded, and S3 objects will be deleted after they have been downloaded.
isBatchMode - If true, uploads or downloads will proceed in batches rather than all at once. This mode is useful for large buckets where listing all the objects and their details at once may consume a large amount of time and memory.
isSkipMetadata - If true, no metadata information about objects will be downloaded from S3. This will make the synchronize process faster, but it will also reduce the amount of information Synchronize will have to make decisions.
isNoDelete - Files will not be deleted if true, but may be replaced.
isGzipEnabled - Files will be gzipped prior to upload if true.
isEncryptionEnabled - Files will be encrypted prior to upload if true.
reportLevel - The level or amount of reporting to perform. The default value is REPORT_LEVEL_ALL.
properties - The configuration properties that will be used by this instance.
Method Detail

uploadLocalDirectoryToS3

public void uploadLocalDirectoryToS3(java.util.Map filesMap,
                                     S3Bucket bucket,
                                     java.lang.String rootObjectPath,
                                     java.lang.String aclString,
                                     BytesProgressWatcher progressWatcher)
                              throws java.lang.Exception
Copies the contents of a local directory to S3, storing them in the given root path.

A set of comparisons is used to determine exactly how the local files differ from the contents of the S3 location, and files are transferred based on these comparisons and options set by the user.

The following S3 Object properties are set when a file is uploaded:

The following jets3t-specific metadata items are also set:

Parameters:
filesMap - a map of the local Files with '/'-delimited file paths as keys
bucket - the bucket to put the objects in (will be created if necessary)
rootObjectPath - the root path where objects are put (will be created if necessary)
aclString - the ACL to apply to the uploaded object
progressWatcher - a class that reports on the progress of this method
Throws:
java.lang.Exception

restoreFromS3ToLocalDirectory

public void restoreFromS3ToLocalDirectory(java.util.Map filesMap,
                                          java.lang.String rootObjectPath,
                                          java.io.File localDirectory,
                                          S3Bucket bucket,
                                          BytesProgressWatcher progressWatcher)
                                   throws java.lang.Exception
Copies the contents of a root path in S3 to the local file system.

A set of comparisons is used to determine exactly how the S3 objects/files differ from the local target, and files are transferred based on these comparisons and options set by the user.

If an object is gzipped (according to its Content-Type) and the gzip option is set, the object is inflated. If an object is encrypted (according to the metadata item Constants.METADATA_JETS3T_CRYPTO_ALGORITHM) and the crypt option is set, the object is decrypted. If encrypted and/or gzipped objects are restored without the corresponding option being set, the user will be responsible for inflating or decrypting the data.

Note: If a file was backed-up with both encryption and gzip options it cannot be restored with only the gzip option set, as files are gzipped prior to being encrypted and cannot be inflated without first being decrypted.

Parameters:
filesMap - a map of the local Files with '/'-delimited file paths as keys
rootObjectPath - the root path in S3 where backed-up objects were stored
localDirectory - the directory to which the S3 objects will be restored
bucket - the bucket into which files were backed up
progressWatcher - a class that reports on the progress of this method
Throws:
java.lang.Exception

run

public void run(java.lang.String s3Path,
                java.util.List fileList,
                java.lang.String actionCommand,
                java.lang.String cryptoPassword,
                java.lang.String aclString)
         throws java.lang.Exception
Runs the application, performing the action specified on the given S3 and local directory paths.

Parameters:
s3Path - the path in S3 (including the bucket name) to which files are backed-up, or from which files are restored.
fileList - a list one or more of File objects for Uploads, or a single target directory for Downloads.
actionCommand - the action to perform, UP(load) or DOWN(load)
cryptoPassword - if non-null, an EncryptionUtil object is created with the provided password to encrypt or decrypt files.
aclString - the ACL to apply to the uploaded object
Throws:
java.lang.Exception

main

public static void main(java.lang.String[] args)
                 throws java.lang.Exception
Runs this application from the console, accepts and checks command-line parameters and runs an upload or download operation when all the necessary parameters are provided.

Throws:
java.lang.Exception