Ce contenu n'est pas disponible dans la langue sélectionnée.

Chapter 22. Copying files to or from a container


22.1. Overview

You can use the CLI to copy local files to or from a remote directory in a container.

You can use the CLI to copy local files to or from a remote directory in a container. This is a useful tool for copying database archives to and from your pods for backup and restore purposes. It can also be used to copy source code changes into a running pod for development debugging, when the running pod supports hot reload of source files.

22.2. Basic Usage

Support for copying local files to or from a container is built into the CLI:

$ oc rsync <source> <destination> [-c <container>]
Copy to Clipboard Toggle word wrap

For example:

# Copy local directory to a pod directory
$ oc rsync /home/user/source devpod1234:/src

# Copy pod directory to a local directory
$ oc rsync devpod1234:/src /home/user/source
Copy to Clipboard Toggle word wrap

22.3. Requirements

The oc rsync command uses the local rsync command if present on the client’s machine. This requires that the remote container also have the rsync command. If rsync is not found locally or in the remote container, then a tar archive will be created locally and sent to the container where tar will be used to extract the files. If tar is not available in the remote container, then the copy will fail.

Note

The tar copy method does not provide the same functionality as rsync. For example, rsync will create the destination directory if it doesn’t exist and will only send files that are different between the source and the destination.

Note

In Windows, the cwRsync client should be installed and added to the PATH for use with oc rsync

22.4. Specifying the copy source

The source argument of the oc rsync command must point to either a local directory or a pod directory. Individual files are not currently supported. When specifying a pod directory the directory name must be prefixed with the pod name: <pod name>:<dir>. Just as with UNIX rsync, if the directory name ends in a path separator ('/'), only the contents of the directory are copied to the destination. Otherwise, the directory itself is copied to the destination with all its contents.

22.5. Specifying the copy destination

The destination argument of the oc rsync command must point to a directory. If the directory does not exist, but rsync is used for copy, the directory is created for you.

22.6. Deleting files at the destination

The --delete flag may be used to delete any files in the remote directory that are not in the local directory.

Retour au début
Red Hat logoGithubredditYoutubeTwitter

Apprendre

Essayez, achetez et vendez

Communautés

À propos de la documentation Red Hat

Nous aidons les utilisateurs de Red Hat à innover et à atteindre leurs objectifs grâce à nos produits et services avec un contenu auquel ils peuvent faire confiance. Découvrez nos récentes mises à jour.

Rendre l’open source plus inclusif

Red Hat s'engage à remplacer le langage problématique dans notre code, notre documentation et nos propriétés Web. Pour plus de détails, consultez le Blog Red Hat.

À propos de Red Hat

Nous proposons des solutions renforcées qui facilitent le travail des entreprises sur plusieurs plates-formes et environnements, du centre de données central à la périphérie du réseau.

Theme

© 2025 Red Hat