Welcome to the upcoming version of the MinIO Documentation! The content on this page is under active development and may change at any time. If you can't find what you're looking for, check our legacy documentation. Thank you for your patience.

mc cp

Description

The mc cp command copies data from one or more sources to a target S3-compatible service.

Copy Object to S3

Use mc cp to copy an object to an S3-compatible host:

mc cp SOURCE ALIAS/PATH
  • Replace SOURCE with the filesystem path to the object.

  • Replace ALIAS with the alias of a configured S3-compatible host.

  • Replace PATH with the path to the object on the S3-compatible host. You can specify a different object name to “rename” the object on copy.

mc cp SRCALIAS/SRCPATH TGTALIAS/TGTPATH
  • Replace SRCALIAS with the alias of a source S3-compatible host.

  • Replace SRCPATH with the path to the object on the S3-compatible host.

  • Replace TGTALIAS with the alias of a target S3-compatible host.

  • Replace TGTPATH with the path to the object on a target S3-compatible host. Omit the object name to use the SRCPATH object name.

Recursively Copy Objects to S3

Use mc cp --recursive to recursively copy objects to an S3-compatible host:

mc cp --recursive SOURCE ALIAS/PATH
  • Replace SOURCE with the filesystem path to the directory containing the file(s).

  • Replace ALIAS with the alias of a configured S3-compatible host.

  • Replace PATH with the path to the object on the S3-compatible host. mc cp uses the SOURCE filenames when creating the objects on the target host.

mc cp --recursive SRCALIAS/SRCPATH TGTALIAS/TGTPATH
  • Replace SRCALIAS with the alias of a source S3-compatible host.

  • Replace SRCPATH with the path to the bucket or bucket prefix on the source S3-compatible host.

  • Replace TGTALIAS with the alias of a target S3-compatible host.

  • Replace TGTPATH with the path to the object on the target S3-compatible host. mc cp uses the SRCPATH object names when creating objects on the target host.

Copy Point-In-Time Version of Object

Use mc cp --rewind to copy an object as it existed at a specific point in time. This command only applies to S3-to-S3 copy.

mc cp --rewind DURATION SRCALIAS/SRCPATH TGTALIAS/TGTPATH
  • Replace DURATION with the point-in-time in the past at which the command copies the object. For example, specify 30d to copy the version of the object 30 days prior to the current date.

  • Replace SRCALIAS with the alias of a source S3-compatible host.

  • Replace SRCPATH with the path to the object on the source S3-compatible host.

  • Replace TGTALIAS with the alias of a target S3-compatible host.

  • Replace TGTPATH with the path to the object on the target S3-compatible host. Omit the object name to use the SRCPATH object name.

Requires Versioning

mc cp requires bucket versioning to use this feature. Use mc version to enable versioning on a bucket.

Copy Specific Version of Object

Use mc cp --version-id to copy a specific version of an object. This command only applies to S3-to-S3 copy.

mc cp --version-id VERSION SRCALIAS/SRCPATH TGTALIAS/TGTPATH
  • Replace VERSION with the version of the object to copy.

  • Replace SRCALIAS with the alias of a source S3-compatible host.

  • Replace SRCPATH with the path to the object on the source S3-compatible host.

  • Replace TGTALIAS with the alias of a target S3-compatible host.

  • Replace TGTPATH with the path to the object on the target S3-compatible host. Omit the object name to use the SRCPATH object name.

Requires Versioning

mc cp requires bucket versioning to use this feature. Use mc version to enable versioning on a bucket.

Syntax

mc cp has the following syntax:

mc cp [FLAGS] SOURCE [SOURCE...] TARGET

cp supports the following arguments:

SOURCE

REQUIRED

The object or objects to copy. You can specify both local paths and S3 paths using a configured S3 service alias.

For example:

mc cp play/mybucket/object.txt ~/localfiles/mybucket/object.txt TARGET

If you specify a directory or bucket to SOURCE, you must also specify --recursive to recursively copy the contents of that directory or bucket. If you omit the --recursive argument, cp only copies objects in the top level of the specified directory or bucket.

TARGET

REQUIRED

The full path to the bucket to copy the specified SOURCE to. Specify the alias of a configured S3 service as the prefix to the TARGET path.

For example:

mc cp ~/localfiles/object.txt play/mybucket/
--recursive, --r

Recursively copy the contents of each bucket or directory SOURCE to the TARGET bucket.

--rewind

Directs mc cp to operate only on the object version(s) that existed at specified point-in-time.

  • To rewind to a specific date in the past, specify the date as an ISO8601-formatted timestamp. For example: --rewind "2020.03.24T10:00".

  • To rewind a duration in time, specify the duration as a string in #d#hh#mm#ss format. For example: --rewind "1d2hh3mm4ss".

--rewind requires that the specified --SOURCE be an S3-compatible service that supports Bucket Versioning. For MinIO deployments, use mc version to enable or disable bucket versioning.

--version-id, --vid

Directs mc cp to operate only on the specified object version.

--version-id requires that the specified --SOURCE be an S3-compatible service that supports Bucket Versioning. For MinIO deployments, use mc version to enable or disable bucket versioning.

--older-than

Remove object(s) older than the specified time limit. Specify a string in #d#hh#mm#ss format. For example: --older-than 1d2hh3mm4ss

Defaults to 0 (all objects).

--newer-than

Remove object(s) newer than the specified number of days. Specify a string in #d#hh#mm#ss format. For example: --older-than 1d2hh3mm4ss

Defaults to 0 (all objects).

--storage-class, --sc

Set the storage class for the new object(s) on the TARGET.

See AmazonS3/latest/dev/storage-class-intro.html for more information on S3 storage classses.

--preserve, --a

Preserve file system attributes and bucket policy rules of the SOURCE directories, buckets, and objects on the TARGET bucket(s).

--attr

Add custom metadata for the object. Specify key-value pairs as KEY=VALUE\;. For example, --attr key1=value1\;key2=value2\;key3=value3.

--continue, --c

Create or resume a copy session.

--encrypt

Encrypt or decrypt objects using server-side encryption with server-managed keys. Specify key-value pairs as KEY=VALUE.

  • Each KEY represents a bucket or object.

  • Each VALUE represents the data key to use for encrypting

    object(s).

Enclose the entire list of key-value pairs passed to --encrypt in double-quotes ".

--encrypt can use the MC_ENCRYPT environment variable for retrieving a list of encryption key-value pairs as an alternative to specifying them on the command line.

--encrypt-key

Encrypt or decrypt objects using server-side encryption with client-specified keys. Specify key-value pairs as KEY=VALUE.

  • Each KEY represents a bucket or object.

  • Each VALUE represents the data key to use for encrypting

    object(s).

Enclose the entire list of key-value pairs passed to --encrypt-key in double quotes ".

--encrypt-key can use the MC_ENCRYPT_KEY environment variable for retrieving a list of encryption key-value pairs as an alternative to specifying them on the command line.

Behavior

mc cp verifies all copy operations to object storage using MD5SUM checksums.

Interrupted or failed copy operations can resume from the point of failure by issuing the mc cp operation again with the --continue argument.

Examples

Copy a text file to an object storage.

The following example assumes that the play alias exists in the mc configuration file. You can replace play with the alias for your preferred S3-compatible deployment.

See mc alias for more information on aliases.

mc cp myobject.txt play/mybucket

Copy a text file to an object storage with specified metadata.

The following example assumes that the play alias exists in the mc configuration file. You can replace play with the alias for your preferred S3-compatible deployment.

See mc alias for more information on aliases.

mc cp --attr key1=value1;key2=value2 myobject.txt play/mybucket

Copy a folder recursively from MinIO cloud storage to Amazon S3 cloud storage with specified metadata.

The following example assumes that the play alias exists in the mc configuration file. You can replace play with the alias for your preferred S3-compatible deployment.

See mc alias for more information on aliases.

 mc cp --attr Cache-Control=max-age=90000,min-fresh=9000\;key1=value1\;key2=value2 \
   --recursive play/mybucket/bucketname/ s3/mybucket/

Copy a text file to an object storage and assign storage-class REDUCED_REDUNDANCY to the uploaded object.

The following example assumes that the play alias exists in the mc configuration file. You can replace play with the alias for your preferred S3-compatible deployment.

See mc alias for more information on aliases.

mc cp --storage-class REDUCED_REDUNDANCY myobject.txt play/mybucket

Copy a server-side encrypted file to an object storage.

The following example assumes that the s3 and myminio aliases exists in the mc configuration file. See mc alias for more information on aliases.

mc cp --recursive \
  --encrypt-key "s3/documents/=32byteslongsecretkeymustbegiven1 , myminio/documents/=32byteslongsecretkeymustbegiven2" \
  s3/documents/myobject.txt myminio/documents/

Perform key-rotation on a server-side encrypted object.

mc cp key rotation requires creating an additional alias with the same endpoing as the target S3 service alias. mc cp effectively decrypts the object using the old secret key, encrypts the object using the new secret key, and replaces the old object with the newly encrypted object.

The following example assumes that the myminio1 and myminio2 aliases exists in the mc configuration file. See mc alias for more information on aliases.

mc cp --encrypt-key 'myminio1/mybucket=32byteslongsecretkeymustgenerate , myminio2/mybucket/=32byteslongsecretkeymustgenerat1' \
  myminio1/mybucket/encryptedobject myminio2/mybucket/encryptedobject

Copy a javascript file to object storage and assign Cache-Control header to the uploaded object

The following example assumes that the play alias exists in the mc configuration file. You can replace play with the alias for your preferred S3-compatible deployment.

See mc alias for more information on aliases.

mc cp --attr Cache-Control=no-cache myscript.js play/mybucket

Copy a text file to an object storage and preserve the filesyatem attributes.

The following example assumes that the play alias exists in the mc configuration file. You can replace play with the alias for your preferred S3-compatible deployment.

See mc alias for more information on aliases.

mc cp -a myobject.txt play/mybucket