This documentation is for a release that is no longer maintained
See documentation for the latest supported version 3 or the latest supported version 4.이 콘텐츠는 선택한 언어로 제공되지 않습니다.
Chapter 24. Copying Files to or from a Container
24.1. Overview 링크 복사링크가 클립보드에 복사되었습니다!
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.
24.2. Basic Usage 링크 복사링크가 클립보드에 복사되었습니다!
Support for copying local files to or from a container is built into the CLI:
oc rsync <source> <destination> [-c <container>]
$ oc rsync <source> <destination> [-c <container>]
For example, to copy a local directory to a pod directory:
oc rsync /home/user/source devpod1234:/src
$ oc rsync /home/user/source devpod1234:/src
Or to copy a pod directory to a local directory:
oc rsync devpod1234:/src /home/user/source
$ oc rsync devpod1234:/src /home/user/source
24.3. Backing Up and Restoring Databases 링크 복사링크가 클립보드에 복사되었습니다!
Use oc rsync
to copy database archives from an existing database container to a new database container’s persistent volume directory.
MySQL is used in the example below. Replace mysql|MYSQL
with pgsql|PGSQL
or mongodb|MONGODB
and refer to the migration guide to find the exact commands for each of our supported database images. The example assumes an existing database container.
Back up the existing database from a running database pod:
oc rsh <existing db container> mkdir /var/lib/mysql/data/db_archive_dir mysqldump --skip-lock-tables -h ${MYSQL_SERVICE_HOST} -P ${MYSQL_SERVICE_PORT:-3306} \ -u ${MYSQL_USER} --password="$MYSQL_PASSWORD" --all-databases > /var/lib/mysql/data/db_archive_dir/all.sql exit
$ oc rsh <existing db container> # mkdir /var/lib/mysql/data/db_archive_dir # mysqldump --skip-lock-tables -h ${MYSQL_SERVICE_HOST} -P ${MYSQL_SERVICE_PORT:-3306} \ -u ${MYSQL_USER} --password="$MYSQL_PASSWORD" --all-databases > /var/lib/mysql/data/db_archive_dir/all.sql # exit
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Remote sync the archive file to your local machine:
oc rsync <existing db container with db archive>:/var/lib/mysql/data/db_archive_dir /tmp/.
$ oc rsync <existing db container with db archive>:/var/lib/mysql/data/db_archive_dir /tmp/.
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Start a second MySQL pod into which to load the database archive file created above. The MySQL pod must have a unique
DATABASE_SERVICE_NAME
.Copy to Clipboard Copied! Toggle word wrap Toggle overflow - 1
mysql
is the default. In this example,mysql2
is created.
Use the appropriate commands to restore the database in the new database container from the copied database archive directory:
MySQL
cd /var/lib/mysql/data/db_archive_dir mysql -u root source all.sql GRANT ALL PRIVILEGES ON <dbname>.* TO '<your username>'@'localhost'; FLUSH PRIVILEGES; cd ../; rm -rf /var/lib/mysql/data/db_backup_dir
$ cd /var/lib/mysql/data/db_archive_dir $ mysql -u root $ source all.sql $ GRANT ALL PRIVILEGES ON <dbname>.* TO '<your username>'@'localhost'; FLUSH PRIVILEGES; $ cd ../; rm -rf /var/lib/mysql/data/db_backup_dir
Copy to Clipboard Copied! Toggle word wrap Toggle overflow You now have two MySQL database pods running in your project with the archived database.
24.4. 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
creates the destination directory if it does not 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 the oc rsync
command.
24.5. 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>
<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.
24.6. 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.
24.7. 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.