Este contenido no está disponible en el idioma seleccionado.
Chapter 6. Project-level tasks
6.1. Backing up a project Copiar enlaceEnlace copiado en el portapapeles!
Creating a backup of all relevant data involves exporting all important information, then restoring into a new project.
Because the oc get all command returns only certain project resources, you must separately back up other resources, including PVCs and Secrets, as shown in the following steps.
Procedure
List the project data to back up:
oc get all
$ oc get allCopy to Clipboard Copied! Toggle word wrap Toggle overflow Example Output
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Export the project objects to a
project.yamlfile.oc get -o yaml --export all > project.yaml
$ oc get -o yaml --export all > project.yamlCopy to Clipboard Copied! Toggle word wrap Toggle overflow Export other objects in your project, such as role bindings, secrets, service accounts, and persistent volume claims.
You can export all namespaced objects in your project using the following command:
for object in $(oc api-resources --namespaced=true -o name) do oc get -o yaml --export $object > $object.yaml done
$ for object in $(oc api-resources --namespaced=true -o name) do oc get -o yaml --export $object > $object.yaml doneCopy to Clipboard Copied! Toggle word wrap Toggle overflow Note that some resources cannot be exported, and a
MethodNotAllowederror is displayed.Some exported objects can rely on specific metadata or references to unique IDs in the project. This is a limitation on the usability of the recreated objects.
When using
imagestreams, theimageparameter of adeploymentconfigcan point to a specificshachecksum of an image in the internal registry that would not exist in a restored environment. For instance, running the sample "ruby-ex" asoc new-app centos/ruby-22-centos7~https://github.com/sclorg/ruby-ex.gitcreates animagestreamruby-exusing the internal registry to host the image:oc get dc ruby-ex -o jsonpath="{.spec.template.spec.containers[].image}"$ oc get dc ruby-ex -o jsonpath="{.spec.template.spec.containers[].image}" 10.111.255.221:5000/myproject/ruby-ex@sha256:880c720b23c8d15a53b01db52f7abdcbb2280e03f686a5c8edfef1a2a7b21ceeCopy to Clipboard Copied! Toggle word wrap Toggle overflow If importing the
deploymentconfigas it is exported withoc get --exportit fails if the image does not exist.
6.2. Restoring a project Copiar enlaceEnlace copiado en el portapapeles!
To restore a project, create the new project, then restore any exported files by running oc create -f <file_name>.
Procedure
Create the project:
oc new-project <project_name>
$ oc new-project <project_name>1 Copy to Clipboard Copied! Toggle word wrap Toggle overflow - 1
- This
<project_name>value must match the name of the project that was backed up.
Import the project objects:
oc create -f project.yaml
$ oc create -f project.yamlCopy to Clipboard Copied! Toggle word wrap Toggle overflow Import any other resources that you exported when backing up the project, such as role bindings, secrets, service accounts, and persistent volume claims:
oc create -f <object>.yaml
$ oc create -f <object>.yamlCopy to Clipboard Copied! Toggle word wrap Toggle overflow Some resources might fail to import if they require another object to exist. If this occurs, review the error message to identify which resources must be imported first.
Some resources, such as pods and default service accounts, can fail to be created.
6.3. Backing up persistent volume claims Copiar enlaceEnlace copiado en el portapapeles!
You can synchronize persistent data from inside of a container to a server.
Depending on the provider that is hosting the OpenShift Container Platform environment, the ability to launch third party snapshot services for backup and restore purposes also exists. As OpenShift Container Platform does not have the ability to launch these services, this guide does not describe these steps.
Consult any product documentation for the correct backup procedures of specific applications. For example, copying the mysql data directory itself does not create a usable backup. Instead, run the specific backup procedures of the associated application and then synchronize any data. This includes using snapshot solutions provided by the OpenShift Container Platform hosting platform.
Procedure
View the project and pods:
oc get pods
$ oc get pods NAME READY STATUS RESTARTS AGE demo-1-build 0/1 Completed 0 2h demo-2-fxx6d 1/1 Running 0 1hCopy to Clipboard Copied! Toggle word wrap Toggle overflow Describe the desired pod to find the volumes that are currently used by a persistent volume:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow This output shows that the persistent data is in the
/opt/app-root/src/uploadeddirectory.Copy the data locally:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow The
ocp_sop.txtfile is downloaded to the local system to be backed up by backup software or another backup mechanism.NoteYou can also use the previous steps if a pod starts without needing to use a
pvc, but you later decide that apvcis necessary. You can preserve the data and then use the restorate process to populate the new storage.
6.4. Restoring persistent volume claims Copiar enlaceEnlace copiado en el portapapeles!
You can restore persistent volume claim (PVC) data that you backed up. You can delete the file and then place the file back in the expected location or migrate the persistent volume claims. You might migrate if you need to move the storage or in a disaster scenario when the backend storage no longer exists.
Consult any product documentation for the correct restoration procedures for specific applications.
6.4.1. Restoring files to an existing PVC Copiar enlaceEnlace copiado en el portapapeles!
Procedure
Delete the file:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Replace the file from the server that contains the rsync backup of the files that were in the pvc:
oc rsync uploaded demo-2-fxx6d:/opt/app-root/src/
$ oc rsync uploaded demo-2-fxx6d:/opt/app-root/src/Copy to Clipboard Copied! Toggle word wrap Toggle overflow Validate that the file is back on the pod by using
oc rshto connect to the pod and view the contents of the directory:oc rsh demo-2-fxx6d
$ oc rsh demo-2-fxx6d sh-4.2$ *ls /opt/app-root/src/uploaded/* lost+found ocp_sop.txtCopy to Clipboard Copied! Toggle word wrap Toggle overflow
6.4.2. Restoring data to a new PVC Copiar enlaceEnlace copiado en el portapapeles!
The following steps assume that a new pvc has been created.
Procedure
Overwrite the currently defined
claim-name:oc set volume dc/demo --add --name=persistent-volume \ --type=persistentVolumeClaim --claim-name=filestore \ --mount-path=/opt/app-root/src/uploaded --overwrite
$ oc set volume dc/demo --add --name=persistent-volume \ --type=persistentVolumeClaim --claim-name=filestore \ --mount-path=/opt/app-root/src/uploaded --overwriteCopy to Clipboard Copied! Toggle word wrap Toggle overflow Validate that the pod is using the new PVC:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Now that the deployment configuration uses the new
pvc, runoc rsyncto place the files onto the newpvc:Copy to Clipboard Copied! Toggle word wrap Toggle overflow Validate that the file is back on the pod by using
oc rshto connect to the pod and view the contents of the directory:oc rsh demo-3-2b8gs
$ oc rsh demo-3-2b8gs sh-4.2$ ls /opt/app-root/src/uploaded/ lost+found ocp_sop.txtCopy to Clipboard Copied! Toggle word wrap Toggle overflow
6.5. Pruning images and containers Copiar enlaceEnlace copiado en el portapapeles!
See the Pruning Resources topic for information about pruning collected data and older versions of objects.