---
title: Copying files to or from OpenShift Container Platform containers
---

# Copying files to or from OpenShift Container Platform containers {#nodes-containers-copying-files}

You can use the `oc rsync` command, or remote sync, to copy local files to or from a remote directory in a OpenShift Container Platform container.

The `oc rsync` command leverages the local Rsync tool on the client machine and the remote container for tasks such as copying database archives to and from your pods for backup and restore purposes, or copying source code changes into a running pod for development debugging.

> [!NOTE]
> If the Rsync tool is not found locally or in the remote container, a **tar** archive is created locally and sent to the container where the **tar** utility is used to extract the files. If **tar** is not available in the remote container, the copy fails.

## Understanding how to copy files {#nodes-containers-copying-files-about_nodes-containers-copying-files}

You can use the `oc rsync` command, or remote sync, for copying database archives to and from your pods for backup and restore purposes. You can also use `oc rsync` to copy source code changes into a running pod for development debugging, when the running pod supports hot reload of source files.

```terminal
$ oc rsync <source> <destination> [-c <container>]
```

When using the `oc rysnc` command, note the following requirements.

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

    When specifying a pod directory, the directory name must be prefixed with the pod name:

    ```terminal
    <pod name>:<dir>
    ```

    If the directory name ends in a path separator (`/`), only the contents of the directory are copied to the destination. Otherwise, the directory and its contents are copied to the destination.

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.

Deleting Files at the Destination
:   The `--delete` flag can be used to delete any files in the remote directory that are not in the local directory.

Continuous Syncing on File Change
:   Using the `--watch` option causes the command to monitor the source path for any file system changes, and synchronizes changes when they occur. With this argument, the command runs continuously.

    Synchronization occurs after short quiet periods to ensure a rapidly changing file system does not result in continuous synchronization calls.

    When using the `--watch` option, the behavior is effectively the same as manually invoking `oc rsync` repeatedly, including any arguments normally passed to `oc rsync`. Therefore, you can control the behavior via the same flags used with manual invocations of `oc rsync`, such as `--delete`.

## Copying files to and from containers {#nodes-containers-copying-files-procedure_nodes-containers-copying-files}

You can use the `oc rsync` command for copying local files to or from a container.

**Prerequisites**

- rsync must be installed. The `oc rsync` command uses the local `rsync` tool, if present on the client machine and the remote container.

  If `rsync` is not found locally or in the remote container, a **tar** archive is created locally and sent to the container where the **tar** utility is used to extract the files. If **tar** is not available in the remote container, the copy will fail.

  The **tar** copy method does not provide the same functionality as `oc rsync`. For example, `oc rsync` creates the destination directory if it does not exist and only sends 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 the `oc rsync` command.

**Procedure**

- To copy a local directory to a pod directory:

  ```terminal
  $ oc rsync <local-dir> <pod-name>:/<remote-dir> -c <container-name>
  ```

  For example:

  ```terminal
  $ oc rsync /home/user/source devpod1234:/src -c user-container
  ```
- To copy a pod directory to a local directory:

  ```terminal
  $ oc rsync devpod1234:/src /home/user/source
  ```

  ```terminal {title="Example output"}
  $ oc rsync devpod1234:/src/status.txt /home/user/
  ```

## Using advanced Rsync features {#nodes-containers-copying-files-rsync_nodes-containers-copying-files}

You can use the additional command-line options that are available with the standard `rsync` command if needed.

The `oc rsync` command exposes fewer command-line options than standard `rsync` command. In the case that you want to use a standard `rsync` command-line option that is not available with the `oc rsync` command, for example the `--exclude-from=FILE` option, it might be possible to use standard `rsync` with the `--rsh` (`-e`) option or `RSYNC_RSH` environment variable as a workaround, as shown in the following examples:

```terminal
$ rsync --rsh='oc rsh' --exclude-from=<file_name> <local-dir> <pod-name>:/<remote-dir>
```

or:

Export the `RSYNC_RSH` variable:

```terminal
$ export RSYNC_RSH='oc rsh'
```

Then, run the rsync command:

```terminal
$ rsync --exclude-from=<file_name> <local-dir> <pod-name>:/<remote-dir>
```

Both of the above examples configure the standard `rsync` command to use `oc rsh` as its remote shell program to enable it to connect to the remote pod, and are an alternative to running `oc rsync`.
