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 mv

Description

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

Checksum Verification

mc mv verifies all move operations to object storage using MD5SUM checksums.

Resume Move Operations

Use mc mv --continue to resume an interrupted or failed move operation from the point of failure.

MinIO Trims Empty Prefixes on Object Removal

mc mv relies on the mc removal API for deleting objects. As part of removing the last object in a bucket prefix, mc also recursively removes each empty part of the prefix up to the bucket root. mc only applies the recursive removal to prefixes created implicitly as part of object write operations - that is, the prefix was not created using an explicit directory creation command such as mc mb.

For example, consider a bucket photos with the following object prefixes:

  • photos/2021/january/myphoto.jpg

  • photos/2021/february/myotherphoto.jpg

  • photos/NYE21/NewYears.jpg

photos/NYE21 is the only prefix explicitly created using mc mb. All other prefixes were implicitly created as part of writing the object located at that prefix.

If an mc command removes myphoto.jpg, the removal API automatically trims the empty /january prefix. If a subsequent mc command removes myotherphoto.jpg, the removal API automatically trims both the /february prefix and the now-empty /2021 prefix. If an mc command removes NewYears.jpg, the /NYE21 prefix remains in place since it was explicitly created.

If using mc mv for operations on a filesystem, mc applies this same behavior by recursively trimming empty directory paths up to the root. However, the mc remove API cannot distinguish between an explicitly created directory path and an implicitly created one. If mc mv deletes the last object at a filesystem path, mc recursively deletes all empty directories within that path up to the root as part of the removal operation.

Examples

Move Files from Filesystem to S3-Compatible Host

mc mv [--recursive] FILEPATH ALIAS/PATH
  • Replace FILEPATH with the full file path to the file to move.

    If specifying the path to a directory, include the --recursive flag.

    mc mv removes the files from the source after successfully moving it to the destination.

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

  • Replace PATH with the destination bucket.

Move a File from Filesystem to S3-Compatible Host with Custom Metadata

Use mc mv with the --attr option to set custom attributes on file(s).

mc mv --attr "ATTRIBUTES" FILEPATH ALIAS/PATH
  • Replace FILEPATH with the full file path to the file to move. mc mv removes the file from the source after successfully moving it to the destination.

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

  • Replace PATH with the destination bucket.

  • Replace ATTRIBUTES with one or more comma-separated key-value pairs KEY=VALUE. Each pair represents one attribute key and value.

Move Bucket Between S3-Compatible Services

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

  • Replace SRCPATH with the path to the bucket. mc mv removes the bucket and its contents from the source after successfully moving it to the destination.

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

  • Replace TGTPATH with the path to the bucket.

Move File to S3-Compatible Host with Specific Storage Class

Use mc mv with the --storage-class option to set the storage class on the destination S3-compatible host.

mc mv --storage-class CLASS FILEPATH ALIAS/PATH
  • Replace CLASS with the storage class to associate to the files.

  • Replace FILEPATH with the full file path to the file to move. mc mv removes the file from the source after successfully moving it to the destination.

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

  • Replace PATH with the destination bucket.

  • Replace ATTRIBUTES with one or more comma-separated key-value pairs KEY=VALUE. Each pair represents one attribute key and value.

    mc mv –storage-class REDUCED_REDUNDANCY myobject.txt play/mybucket

Syntax

mv has the following syntax:

mc mv [FLAGS] SOURCE [SOURCE...] TARGET

mv supports the following arguments:

SOURCE

REQUIRED

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

For example:

mc mv 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 move the contents of that directory. If you omit the --recursive argument, mv only moves objects in the top level of the specified directory or bucket.

TARGET

REQUIRED

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

For example:

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

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

--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: --newer-than 1d2hh3mm4ss.

Defaults to 0 (all objects).

--storage-class, --sc

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

See the Amazon documentation on Storage Classes 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 move 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.