13 KiB
mc cp
minio
Table of Contents
mc cp
Description
The mc cp
command
copies data from one or more sources to a target S3-compatible
service.
Examples
Copy Object to S3
Use mc cp
to copy
an object to an S3-compatible host:
Filesystem to S3
mc cp SOURCE ALIAS/PATH
- Replace
SOURCE <mc cp SOURCE>
with the filesystem path to the object. - Replace
ALIAS <mc cp TARGET>
with thealias <mc alias>
of a configured S3-compatible host. - Replace
PATH <mc cp TARGET>
with the path to the object on the S3-compatible host. You can specify a different object name to "rename" the object on copy.
S3 to S3
mc cp SRCALIAS/SRCPATH TGTALIAS/TGTPATH
- Replace
SRCALIAS <mc cp SOURCE>
with thealias <mc alias>
of a source S3-compatible host. - Replace
SRCPATH <mc cp SOURCE>
with the path to the object on the S3-compatible host. - Replace
TGTALIAS <mc cp TARGET>
with thealias <mc alias>
of a target S3-compatible host. - Replace
TGTPATH <mc cp TARGET>
with the path to the object on a target S3-compatible host. Omit the object name to use theSRCPATH
object name.
Recursively Copy Objects to S3
Use mc cp recursive
to recursively copy objects
to an S3-compatible host:
Filesystem to S3
mc cp --recursive SOURCE ALIAS/PATH
- Replace
SOURCE <mc cp SOURCE>
with the filesystem path to the directory containing the file(s). - Replace
ALIAS <mc cp TARGET>
with thealias <mc alias>
of a configured S3-compatible host. - Replace
PATH <mc cp TARGET>
with the path to the object on the S3-compatible host.mc cp
uses theSOURCE
filenames when creating the objects on the target host.
S3 to S3
mc cp --recursive SRCALIAS/SRCPATH TGTALIAS/TGTPATH
- Replace
SRCALIAS <mc cp SOURCE>
with thealias <mc alias>
of a source S3-compatible host. - Replace
SRCPATH <mc cp SOURCE>
with the path to the bucket or bucket prefix on the source S3-compatible host. - Replace
TGTALIAS <mc cp TARGET>
with thealias <mc alias>
of a target S3-compatible host. - Replace
TGTPATH <mc cp TARGET>
with the path to the object on the target S3-compatible host.mc cp
uses theSRCPATH
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 <mc cp rewind>
with the point-in-time in the past at which the command copies the object. For example, specify30d
to copy the version of the object 30 days prior to the current date. - Replace
SRCALIAS <mc cp SOURCE>
with thealias <mc alias>
of a source S3-compatible host. - Replace
SRCPATH <mc cp SOURCE>
with the path to the object on the source S3-compatible host. - Replace
TGTALIAS <mc cp TARGET>
with thealias <mc alias>
of a target S3-compatible host. - Replace
TGTPATH <mc cp TARGET>
with the path to the object on the target S3-compatible host. Omit the object name to use theSRCPATH
object name.
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 <mc cp rewind>
with the version of the object to copy. - Replace
SRCALIAS <mc cp SOURCE>
with thealias <mc alias>
of a source S3-compatible host. - Replace
SRCPATH <mc cp SOURCE>
with the path to the object on the source S3-compatible host. - Replace
TGTALIAS <mc cp TARGET>
with thealias <mc alias>
of a target S3-compatible host. - Replace
TGTPATH <mc cp TARGET>
with the path to the object on the target S3-compatible host. Omit the object name to use theSRCPATH
object name.
Syntax
mc cp
has the
following syntax:
mc cp [FLAGS] SOURCE [SOURCE...] TARGET
~mc 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 <mc alias>
.
For example:
mc cp play/mybucket/object.txt ~/localfiles/mybucket/object.txt TARGET
If you specify a directory or bucket to ~mc cp SOURCE
, you must
also specify ~mc cp recursive
to recursively copy the
contents of that directory or bucket. If you omit the
--recursive
argument, ~mc 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 ~mc cp SOURCE
to. Specify
the alias <mc alias>
of a configured S3 service as
the prefix to the ~mc cp TARGET
path.
For example:
mc cp ~/localfiles/object.txt play/mybucket/
recursive, r
Recursively copy the contents of each bucket or directory ~mc cp SOURCE
to the ~mc cp TARGET
bucket.
rewind
version-id, vid
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 ~mc cp 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 ~mc cp SOURCE
directories,
buckets, and objects on the ~mc cp 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).
- Each
Enclose the entire list of key-value pairs passed to ~mc cp encrypt
in
double-quotes "
.
~mc cp 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).
- Each
Enclose the entire list of key-value pairs passed to ~mc cp encrypt-key
in double quotes "
.
~mc cp 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 ~mc cp continue
argument.
Examples
Copy a text file to an object storage.
mc cp myobject.txt play/mybucket
Copy a text file to an object storage with specified metadata.
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.
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.
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 <mc-configuration>
. 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 <mc-configuration>
. 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
mc cp --attr Cache-Control=no-cache myscript.js play/mybucket
Copy a text file to an object storage and preserve the filesyatem attributes.
mc cp -a myobject.txt play/mybucket