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.Questo contenuto non è disponibile nella lingua selezionata.
Chapter 6. Project-level tasks
6.1. Backing up a project Copia collegamentoCollegamento copiato negli appunti!
Creating a backup of all relevant data involves exporting all important information, then restoring into a new project.
Currently, a OpenShift Container Platform project back up and restore tool is being developed by Red Hat. See the following bug for more information:
Procedure
List all the relevant data to back up:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Export the project objects to a
.yaml
or.json
file.To export the project objects into a
project.yaml
file:oc export all -o yaml > project.yaml
$ oc export all -o yaml > project.yaml
Copy to Clipboard Copied! Toggle word wrap Toggle overflow To export the project objects into a
project.json
file:oc export all -o json > project.json
$ oc export all -o json > project.json
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
Export the project’s
role bindings
,secrets
,service accounts
, andpersistent volume claims
:for object in rolebindings serviceaccounts secrets imagestreamtags podpreset cms egressnetworkpolicies rolebindingrestrictions limitranges resourcequotas pvcs templates cronjobs statefulsets hpas deployments replicasets poddisruptionbudget endpoints do oc export $object -o yaml > $object.yaml done
$ for object in rolebindings serviceaccounts secrets imagestreamtags podpreset cms egressnetworkpolicies rolebindingrestrictions limitranges resourcequotas pvcs templates cronjobs statefulsets hpas deployments replicasets poddisruptionbudget endpoints do oc export $object -o yaml > $object.yaml done
Copy to Clipboard Copied! Toggle word wrap Toggle overflow To list all the namespaced objects:
oc api-resources --namespaced=true -o name
$ oc api-resources --namespaced=true -o name
Copy to Clipboard Copied! Toggle word wrap Toggle overflow 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
, theimage
parameter of adeploymentconfig
can point to a specificsha
checksum 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.git
creates animagestream
ruby-ex
using 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:880c720b23c8d15a53b01db52f7abdcbb2280e03f686a5c8edfef1a2a7b21cee
Copy to Clipboard Copied! Toggle word wrap Toggle overflow If importing the
deploymentconfig
as it is exported withoc export
it fails if the image does not exist.
6.2. Restoring a project Copia collegamentoCollegamento copiato negli appunti!
To restore a project, create the new project, then restore any exported files by running oc create -f pods.json
. However, restoring a project from scratch requires a specific order because some objects depend on others. For example, you must create the configmaps
before you create any pods
.
Procedure
If the project was exported as a single file, import it by running the following commands:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow WarningSome resources, such as pods and default service accounts, can fail to be created.
6.2.1. Backing up persistent volume claims Copia collegamentoCollegamento copiato negli appunti!
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 1h
Copy 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/uploaded
directory.Copy the data locally:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow The
ocp_sop.txt
file 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 apvc
is necessary. You can preserve the data and then use the restorate process to populate the new storage.
6.2.2. Restoring persistent volume claims Copia collegamentoCollegamento copiato negli appunti!
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.2.2.1. Restoring files to an existing PVC Copia collegamentoCollegamento copiato negli appunti!
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 rsh
to 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.txt
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
6.2.2.2. Restoring data to a new PVC Copia collegamentoCollegamento copiato negli appunti!
The following steps assume that a new pvc
has been created.
Procedure
Overwrite the currently defined
claim-name
:oc volume dc/demo --add --name=persistent-volume \ --type=persistentVolumeClaim --claim-name=filestore \ --mount-path=/opt/app-root/src/uploaded --overwrite
$ oc volume dc/demo --add --name=persistent-volume \ --type=persistentVolumeClaim --claim-name=filestore \ --mount-path=/opt/app-root/src/uploaded --overwrite
Copy 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 deployement configuration uses the new
pvc
, runoc rsync
to 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 rsh
to 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.txt
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
6.2.3. Pruning images and containers Copia collegamentoCollegamento copiato negli appunti!
See the Pruning Resources topic for information about pruning collected data and older versions of objects.