Skip to content

eyevinn-osaas/s3-sync

 
 

Repository files navigation

S3 Sync

Script to sync files on one S3 bucket to another S3 bucket

npm github release license

PRs welcome made with hearth by Eyevinn Slack

Badge OSC

Sync files on one S3 bucket to another S3 bucket with support for large files, session tokens, and single file operations.

Features

  • Directory and Single File Sync: Sync entire directories or individual files between S3 buckets
  • Large File Support: Automatic chunked copying for files over 500MB using AWS SDK multipart upload
  • Session Token Support: Compatible with temporary AWS credentials including session tokens
  • Cross-Region Support: Sync between different AWS regions and S3-compatible endpoints
  • Configurable Staging: Customizable local staging directory for operations

Requirements

  • AWS S3 CLI
  • NodeJS 18+

Installation / Usage

Options can be provided either as command line options or environment variables.

Basic Usage

% npx @eyevinn/s3-sync \
  --source-access-key=<source-access-key> \
  --source-secret-key=<source-secret-key> \
  --source-region=<source-region> \
  --dest-endpoint=<dest-endpoint> \
  --dest-access-key=<dest-access-key> \
  --dest-secret-key=<dest-secret-key> \
  s3://source/files/ s3://dest/files/

Single File Copy

% npx @eyevinn/s3-sync \
  --single-file \
  --source-access-key=<source-access-key> \
  --source-secret-key=<source-secret-key> \
  s3://source/large-file.mp4 s3://dest/large-file.mp4

With Session Tokens (for temporary credentials)

% npx @eyevinn/s3-sync \
  --source-access-key=<source-access-key> \
  --source-secret-key=<source-secret-key> \
  --source-session-token=<source-session-token> \
  --dest-access-key=<dest-access-key> \
  --dest-secret-key=<dest-secret-key> \
  --dest-session-token=<dest-session-token> \
  s3://source/files/ s3://dest/files/

Using Environment Variables

Store credentials in a file called .env:

SOURCE_ACCESS_KEY=<source-access-key>
SOURCE_SECRET_KEY=<source-secret-key>
SOURCE_SESSION_TOKEN=<source-session-token>  # Optional
SOURCE_REGION=<source-region>
SOURCE_ENDPOINT=<source-endpoint>             # Optional
DEST_ACCESS_KEY=<dest-access-key>
DEST_SECRET_KEY=<dest-secret-key>
DEST_SESSION_TOKEN=<dest-session-token>       # Optional
DEST_REGION=<dest-region>
DEST_ENDPOINT=<dest-endpoint>                 # Optional
STAGING_DIR=/tmp/data                         # Optional, default: /tmp/data
AWS_CLI_PATH=/usr/local/bin/aws               # Optional, default: aws
% set -a ; source .env ; set +a
% npx @eyevinn/s3-sync s3://source/files s3://dest/files/

Command Line Options

Option Environment Variable Description Default
--source-access-key SOURCE_ACCESS_KEY Source S3 access key -
--source-secret-key SOURCE_SECRET_KEY Source S3 secret key -
--source-session-token SOURCE_SESSION_TOKEN Source S3 session token (for temporary credentials) -
--source-region SOURCE_REGION Source S3 region -
--source-endpoint SOURCE_ENDPOINT Source S3 endpoint (for S3-compatible services) -
--dest-access-key DEST_ACCESS_KEY Destination S3 access key -
--dest-secret-key DEST_SECRET_KEY Destination S3 secret key -
--dest-session-token DEST_SESSION_TOKEN Destination S3 session token (for temporary credentials) -
--dest-region DEST_REGION Destination S3 region -
--dest-endpoint DEST_ENDPOINT Destination S3 endpoint (for S3-compatible services) -
--staging-dir STAGING_DIR Local staging directory /tmp/data
--single-file - Use copy instead of sync for single file operations false
--aws-cli-path AWS_CLI_PATH Full path to AWS CLI executable aws

Large File Handling

Files larger than 500MB are automatically processed using chunked copying with the AWS SDK for improved performance and reliability. This feature:

  • Uses multipart upload for better error recovery
  • Processes files in 100MB chunks
  • Provides progress logging for large transfers
  • Automatically falls back to traditional copy for smaller files

Eyevinn Open Source Cloud

Also available as an open web service in Eyevinn Open Source Cloud. This enables you to synchronize two S3 buckets without having to go through your local computer. Read this documentation for usage instructions.

Development

% npm install
% set -a ; source .env ; set +a
% npm start -- s3://source/files s3://dest/files/

Contributing

See CONTRIBUTING

License

This project is licensed under the MIT License, see LICENSE.

Support

Join our community on Slack where you can post any questions regarding any of our open source projects. Eyevinn's consulting business can also offer you:

  • Further development of this component
  • Customization and integration of this component into your platform
  • Support and maintenance agreement

Contact [email protected] if you are interested.

About Eyevinn Technology

Eyevinn Technology is an independent consultant firm specialized in video and streaming. Independent in a way that we are not commercially tied to any platform or technology vendor. As our way to innovate and push the industry forward we develop proof-of-concepts and tools. The things we learn and the code we write we share with the industry in blogs and by open sourcing the code we have written.

Want to know more about Eyevinn and how it is to work here. Contact us at [email protected]!

About

Sync files from one S3 bucket to another S3 bucket

Resources

License

Contributing

Stars

Watchers

Forks

Packages

No packages published

Languages

  • TypeScript 77.1%
  • JavaScript 19.8%
  • Dockerfile 2.6%
  • Shell 0.5%