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