mc cp
Table of Contents
The mc cp
command copies objects to or from a MinIO deployment, where
the source can MinIO or a local filesystem.
You can also use mc cp
against the local filesystem to produce
similar results to the cp
commandline tool.
The following command copies files from a local filesystem directory
to the mydata
bucket on the myminio
MinIO deployment:
mc cp --recursive ~/mydata/ myminio/mydata/
The mc cp
command has the following syntax:
mc [GLOBALFLAGS] cp \
[--attr "string"] \
[--continue] \
[--disable-multipart] \
[--encrypt "string"] \
[--encrypt-key] \
[--legal-hold "on"] \
[--md5] \
[--newer-than "string"] \
[--older-than "string"] \
[--preserve] \
[--recursive] \
[--retention-mode "string" --retention-duration "string"] \
[--rewind "string"] \
[--storage-class "string"] \
[--tags "string"] \
[--version-id "string"] \
SOURCE [SOURCE ...] \
TARGET
Brackets []
indicate optional parameters.
Parameters sharing a line are mutually dependent.
Parameters seperated using the pipe |
operator are mutually exclusive.
Copy the example to a text editor and modify as-needed before running the command in the terminal/shell.
Required The object or objects to copy.
For copying an object from MinIO, specify the alias and the full path to that object (e.g. bucket and path to object). For example:
mc cp play/mybucket/object.txt ~/mydata/object.txt
Specify multiple SOURCE
paths to copy multiple objects to the
specified TARGET
. mc cp
treats the
last specified alias or filesystem path as the TARGET
. For example:
mc cp ~/data/object.txt myminio/mydata/object.txt play/mydata/object.txt
For copying an object from a local filesystem, specify the full path to that object. For example:
mc cp ~/mydata/object.txt play/mybucket/object.txt
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.
Required The full path to which mc cp
copies the object.
For copying an object to MinIO,
specify the alias
and the full path to that object
(e.g. bucket and path to object). For example:
mc cp ~/mydata/object.txt play/mybucket/object.txt
For copying an object from a local filesystem, specify the full path to that object. For example:
mc cp play/mybucket/object.txt ~/mydata/object.txt
Optional Add custom metadata for the object. Specify key-value pairs as
KEY=VALUE\;
. For example, --attr
key1=value1\;key2=value2\;key3=value3
.
Optional 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.
VALUE
represents the data key to use for encryptingobject(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.
Optional 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.
VALUE
represents the data key to use for encryptingobject(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.
Optional Enables indefinite Legal Hold object locking on the copied objects.
Specify on
.
Optional 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).
Optional 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).
Optional Preserve file system attributes and bucket policy rules of the
SOURCE
directories, buckets, and objects on the
TARGET
bucket(s).
Optional Recursively copy the contents of each bucket or directory
SOURCE
to the TARGET
bucket.
Optional The duration of the WORM retention mode to apply to the copied object(s).
Specify the duration as a string in
#d#hh#mm#ss
format. For example: --retention-duration "1d2hh3mm4ss"
.
Requires specifying --retention-mode
.
Optional enables object locking mode on the copied object(s). Supports the following values:
GOVERNANCE
COMPLIANCE
Requires specifying --retention-duration
.
Optional 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.
Optional 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.
Optional Applies one or more tags to the copied objects.
Specify an ampersand-seperated list of key-value pairs as
KEY1=VALUE1&KEY2=VALUE2
, where each pair represents one tag to
assign to the objects.
Optional 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.
The path to a JSON
formatted configuration file that
mc uses for storing data. See Configuration File for
more information on how mc uses the configuration file.
Enables JSON lines formatted output to the console.
For example:
mc --JSON COMMAND
Disables TLS/SSL certificate verification. Allows TLS connectivity to servers with invalid certificates. Exercise caution when using this option against untrusted S3 hosts.
Displays the current version of mc
.
Use mc cp
to copy an object to an S3-compatible host:
mc cp SOURCE ALIAS/PATH
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.
Use mc cp --recursive
to recursively copy objects to an
S3-compatible host:
mc cp --recursive SOURCE ALIAS/PATH
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.
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.
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.
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.
The mc commandline tool is built for compatibility with the AWS S3 API and is tested MinIO and AWS S3 for expected functionality and behavior.
MinIO provides no guarantees for other S3-compatible services, as their S3 API implementation is unknown and therefore unsupported. While mc commands may work as documented, any such usage is at your own risk.
This work is licensed under a Creative Commons Attribution 4.0 International License.
©2020-Present, MinIO, Inc.