此内容没有您所选择的语言版本。

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>]

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

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.

Red Hat logoGithubRedditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

通过我们的产品和服务,以及可以信赖的内容,帮助红帽用户创新并实现他们的目标。

让开源更具包容性

红帽致力于替换我们的代码、文档和 Web 属性中存在问题的语言。欲了解更多详情,请参阅红帽博客.

關於紅帽

我们提供强化的解决方案,使企业能够更轻松地跨平台和环境(从核心数据中心到网络边缘)工作。

© 2024 Red Hat, Inc.