Skip to content

Upload ​

s3m uploads with the default command:

sh
s3m /path/to/file host/bucket/object

You need a valid configuration first.

Path format ​

txt
host/bucket/object
  • host: name defined in ~/.config/s3m/config.yml
  • bucket: destination bucket
  • object: key stored in the bucket

Regular file uploads ​

For regular files, s3m calculates a checksum before upload and keeps local multipart state under ~/.config/s3m/streams (or $S3M_HOME/streams, see where s3m keeps its files).

  • Files smaller than the multipart buffer are uploaded in a single request.
  • Files larger than the multipart buffer are uploaded in parts and can be resumed.
  • Use s3m --clean to remove the local multipart state.

Example:

sh
s3m /path/to/file backup/backups/dump.sql

Multipart and resumable uploads ​

Large regular files use multipart upload automatically. This is the upload path that creates local stream state and can later be inspected with s3m streams.

  • multipart uploads are used when the file is larger than the effective part size
  • local state is stored under ~/.config/s3m/streams (or $S3M_HOME/streams)
  • interrupted regular file uploads can be resumed
  • transformed uploads such as --pipe, compression, or encryption are not resumed through this path
  • each destination has its own state: the same file uploaded to two keys or two hosts gives two separate entries in s3m streams

Example:

sh
s3m /path/to/large-backup.tar backup/backups/large-backup.tar

A file that changes during the upload ​

Before sending the parts of a multipart upload, and again before completing it, s3m checks that the file still has the size and modification time it had when s3m computed its hash. If the file was cut short, grew, or was rewritten, the upload fails: s3m aborts the multipart upload, clears its saved state and asks you to run the upload again. If the abort fails, the state is kept and the error prints the command to abort it by hand (see left-open uploads).

To upload a file that is still being written, such as a growing log or a dump in progress, use --pipe, for example by piping the program that writes it straight into s3m:

sh
pg_dump mydb | s3m --pipe backup/backups/mydb.sql

Since 0.25.0

A file that grows during a multipart upload fails. Before 0.25.0 it was uploaded with the bytes it had at the start, and a file changed while it was read could be stored as a mix of two versions, with exit code 0.

Multipart uploads left open ​

A multipart upload that does not finish keeps its parts on the server until it is completed or aborted. s3m tries to abort such uploads itself, for example when a streamed (--pipe, compressed or encrypted) upload fails, or when a single-part retry replaces an earlier multipart attempt. If the abort fails, s3m prints the command to run it manually:

sh
s3m rm backup/backups/large-backup.tar --abort <upload-id>

A single-part upload whose abort of the earlier multipart upload fails still exits successfully. Its local state then records the open upload (so s3m streams clean keeps it), and the next run retries the abort without uploading the file again.

After you abort an upload by hand with the command from the error, the next run reports that the upload is gone and removes its state; the run after that starts over.

If the saved multipart upload no longer exists on the server (aborted by hand, by a lifecycle rule, or completed by an earlier run whose answer was lost), the first NoSuchUpload answer ends the run without retries, removes the saved upload, and says that running the upload again starts a new one. This happens only when the host's endpoint, bucket and keys are the ones the upload was started with. If any of them changed, the state is kept and the upload is not aborted: give the host its earlier settings to resume or abort the upload.

An interrupted s3m (killed, or the machine went down) can't abort anything, so keep a bucket lifecycle rule for incomplete multipart uploads, and use s3m ls --multipart to find the ones left behind.

Uploading the same file again ​

s3m remembers each completed upload of a file to a key. When you upload the same file again, unchanged (same content and modification time), to the same key, s3m sends a HEAD request first:

  • if the object is still there with the same ETag, the upload is skipped and the ETag is printed
  • if the object was deleted or changed, or the HEAD request fails (for example credentials that may write but not read), the file is uploaded again

On a bucket that refuses overwrites (Object Lock, bucket lock rules), re-uploading a file that is still there is therefore skipped without an error.

The skip compares only the ETag: -m/--meta, --acl and Object Lock flags given on that run are not applied to the existing object. Use acl or object-lock to change an existing object.

Before 0.24.0

The skip did not check the server: an object deleted after its upload was reported as uploaded again without sending anything.

Output ​

A file upload first prints the BLAKE3 hash that identifies the local file. A successful upload then prints the object's ETag, followed by Expiration, Previous object size, Server-side encryption and Version ID when the server sends them:

txt
blake3: d74981efa70a0c880b8d8c1985d075dbcbf679b99a5f9914e5aaf96b831a9e24
ETag: "d159a38f03a09df9146ce30f7057f7d1-2"
Version ID: 3HL4kqtJlcpXroDTDmJ.rmSpXd3dIbrHY

With --checksum, the value sent to S3 is printed with its algorithm, for example sha256 (base64): ... (see below).

Uploads from --pipe, compressed and encrypted uploads print the same lines from ETag on. Use -q/--quiet to print nothing.

Since 0.25.0

The BLAKE3 line was printed as checksum: <hex>; it is now blake3: <hex> (also in the -v log and the spinner). Scripts that match checksum: need updating. Before 0.25.0, multipart, --pipe, compressed and encrypted uploads printed only the ETag.

PIPE / STDIN ​

You can stream live input with --pipe:

sh
pg_dump mydb | s3m --pipe backup/backups/mydb.sql

STDIN uploads are not resumable after interruption because the original stream cannot be replayed safely.

When the input size is unknown, s3m uses fixed 512 MiB multipart parts for streaming uploads.

When a streaming upload fails, s3m tries to abort its multipart upload (see multipart uploads left open). For interrupted streaming uploads, configure bucket lifecycle rules to clean up incomplete multipart uploads automatically.

--pipe is also the way to upload a file that is still being written: a regular file upload fails if the file changes during the upload.

Compression ​

Enable compression with -x or with compress: true in config.yml:

yaml
---
hosts:
  backup:
    region: us-east-2
    access_key: ACCESS_KEY
    secret_key: SECRET_KEY
    compress: true

Compression uses zstd and sets the content type to application/zstd.

Because the file is transformed while uploading, compressed uploads are not resumable.

Example:

sh
pg_dump mydb | s3m --pipe -x backup/backups/mydb.sql

Metadata ​

Add user-defined object metadata with -m:

sh
s3m /path/to/file backup/backups/file.dat -m "key1=value1;key2=value2"

This creates headers such as:

yaml
x-amz-meta-key1: value1
x-amz-meta-key2: value2

Object Lock (WORM) ​

If the destination bucket has Object Lock enabled, you can apply retention and/or a legal hold while uploading. --object-lock-mode and --retain-until (RFC 3339) must be used together:

sh
s3m /path/to/file backup/vault/file.dat \
  --object-lock-mode COMPLIANCE --retain-until 2027-01-01T00:00:00Z

s3m /path/to/file backup/vault/file.dat --legal-hold

These flags work across every upload path, including --pipe, compression, and encryption. See Object Lock for bucket default retention and for managing retention/legal hold on existing objects.

Additional checksums ​

Supported values for --checksum:

  • crc32
  • crc32c
  • sha1
  • sha256

Example:

sh
s3m /path/to/file backup/backups/file.dat --checksum crc32c

--checksum applies to plain file uploads only: not --pipe, and not with compression or encryption (the --compress flag, or compress / enc_key in the host's config). With compression or encryption it fails before any request:

txt
--checksum can't be used with compression or encryption

The additional checksum replaces Content-MD5 on the upload requests (single-part uploads and each part of a multipart upload); uploads without --checksum still send Content-MD5. This is what Cloudflare R2 requires, which rejects both together.

The upload prints the value sent to S3, which can be compared with the object's x-amz-checksum-*:

txt
sha256 (base64): uU0nuZNNPgilLlLX2n2r+sSE7+N6U4DukIj3rOLvzek=

For a multipart upload it is the composite value, <checksum of the part checksums>-<number of parts>. When the server answers the completion with a composite checksum of the same algorithm, s3m compares it with its own. If they differ, s3m reports both values and says the object was stored, and it clears the finished upload from its saved state, so running the command again uploads the file again.

Multipart uploads ​

Not every server supports every algorithm on the parts of a multipart upload: Cloudflare R2 accepts crc32 and crc32c there, but not sha1 or sha256. When the first parts are rejected because of their checksum (501 NotImplemented), s3m stops, aborts the upload and says what to do:

txt
the server doesn't support sha256 checksums on the parts of a multipart upload, and the upload was aborted. Use another --checksum algorithm (Cloudflare R2 accepts crc32 and crc32c on multipart uploads), or a --buffer larger than the file to upload it as a single part.

A resumed multipart upload (s3m streams resume, or running the same command again) keeps the --checksum it was created with, because the server's upload is bound to it. Running the command again with another --checksum continues with the original one and prints:

txt
warning: resuming the upload in progress with the checksum it was created with (...), not ...

Since 0.25.0

--checksum works on Cloudflare R2, and a resumed upload keeps its checksum. Before, --checksum was silently ignored when the host's config set compress or enc_key.

Anonymous requests ​

For public buckets, use --no-sign-request:

yaml
---
hosts:
  public:
    region: us-east-2
sh
s3m ls public/aws-codedeploy-us-east-2 --no-sign-request

--no-sign-request also uploads to a bucket that allows anonymous writes, multipart and --checksum included (since 0.25.0; before, unsigned uploads were sent without their headers and rejected). A host without keys needs --no-sign-request, see credentials.

Throttle bandwidth ​

Use -k/--kilobytes to limit upload or download rate:

sh
s3m /path/to/file backup/backups/file.dat -k 128

Temporary directory ​

When streaming from STDIN, compressing or encrypting, you can choose where the temporary buffer lives. The default is the system temp directory ($TMPDIR, usually /tmp), and it only needs to exist when such an upload runs:

sh
mariabackup --stream=xbstream | s3m --pipe -t /opt/backup/tmp backup/backups/backup.xb

Encryption ​

To encrypt uploads, add enc_key to config.yml:

yaml
---
hosts:
  backup:
    region: us-east-2
    access_key: ACCESS_KEY
    secret_key: SECRET_KEY
    enc_key: "0123456789abcdef0123456789abcdef"

The key must be exactly 32 characters long.

Encrypted files use CHACHA20-Poly1305 and the content type application/vnd.s3m.encrypted.

Integrity

Each chunk is authenticated, so tampering, reordering, and forged content are detected and decryption fails. Encryption does not detect truncation of a stored object (incomplete downloads are caught at the transport layer). For end-to-end "exactly what I uploaded" assurance, verify restores out-of-band (for example, compare a checksum).

  • encrypted files get the .enc suffix
  • compressed + encrypted files get the .zst.enc suffix
  • encrypted uploads are not resumable because the content is transformed while streaming

If compress is enabled, the data is compressed before it is encrypted.

Released under the BSD License.