Dieser Inhalt ist in der von Ihnen ausgewählten Sprache nicht verfügbar.
Chapter 2. Backing up and restoring projects and applications
You can manually back up and restore data for your projects and applications.
Backup and restore is not guaranteed. You are responsible for backing up your own data.
2.1. Backing up application data Link kopierenLink in die Zwischenablage kopiert!
In many cases, you can back up application data by using the oc rsync command, assuming rsync is installed within the container image. The Red Hat rhel7 base image contains rsync. Therefore, all images that are based on rhel7 contain it as well. See Troubleshooting and Debugging CLI Operations - rsync.
This is a generic backup of application data and does not take into account application-specific backup procedures, for example, special export and import procedures for database systems.
Other means of backup might exist depending on the type of the persistent volume you use, for example, Cinder, NFS, or Gluster.
The paths to back up are also application specific. You can determine what path to back up by looking at the mountPath for volumes in the deploymentconfig.
You can perform this type of application data backup only while the application pod is running.
Procedure
Example of backing up a Jenkins deployment’s application data
Get the application data
mountPathfrom thedeploymentconfig:oc get dc/jenkins -o jsonpath='{ .spec.template.spec.containers[?(@.name=="jenkins")].volumeMounts[?(@.name=="jenkins-data")].mountPath }' /var/lib/jenkins$ oc get dc/jenkins -o jsonpath='{ .spec.template.spec.containers[?(@.name=="jenkins")].volumeMounts[?(@.name=="jenkins-data")].mountPath }' /var/lib/jenkinsCopy to Clipboard Copied! Toggle word wrap Toggle overflow Get the name of the pod that is currently running:
oc get pod --selector=deploymentconfig=jenkins -o jsonpath='{ .metadata.name }' jenkins-1-37nux$ oc get pod --selector=deploymentconfig=jenkins -o jsonpath='{ .metadata.name }' jenkins-1-37nuxCopy to Clipboard Copied! Toggle word wrap Toggle overflow Use the
oc rsynccommand to copy application data:oc rsync jenkins-1-37nux:/var/lib/jenkins /tmp/
$ oc rsync jenkins-1-37nux:/var/lib/jenkins /tmp/Copy to Clipboard Copied! Toggle word wrap Toggle overflow
2.2. Backing up a project Link kopierenLink in die Zwischenablage kopiert!
Creating a backup of all relevant data involves exporting all important information, then restoring into a new project.
Currently, a OpenShift Dedicated 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
.yamlor.jsonfile.To export the project objects into 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 To export the project objects into a
project.jsonfile:oc get -o json --export all > project.json
$ oc get -o json --export all > project.jsonCopy 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 cm egressnetworkpolicies rolebindingrestrictions limitranges resourcequotas pvc templates cronjobs statefulsets hpa deployments replicasets poddisruptionbudget endpoints do oc get -o yaml --export $object > $object.yaml done
$ for object in rolebindings serviceaccounts secrets imagestreamtags cm egressnetworkpolicies rolebindingrestrictions limitranges resourcequotas pvc templates cronjobs statefulsets hpa deployments replicasets poddisruptionbudget endpoints do oc get -o yaml --export $object > $object.yaml doneCopy 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 nameCopy 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, 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}" 10.111.255.221:5000/myproject/ruby-ex@sha256:880c720b23c8d15a53b01db52f7abdcbb2280e03f686a5c8edfef1a2a7b21cee$ 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.
2.3. Restoring application data Link kopierenLink in die Zwischenablage kopiert!
You can restore application data by using the oc rsync command, assuming rsync is installed within the container image. The Red Hat rhel7 base image contains rsync. Therefore, all images that are based on rhel7 contain it as well. See Troubleshooting and Debugging CLI Operations - rsync.
This is a generic restoration of application data and does not take into account application-specific backup procedures, for example, special export and import procedures for database systems.
Other means of restoration might exist depending on the type of the persistent volume you use, for example, Cinder, NFS, or Gluster.
Procedure
Example of restoring a Jenkins deployment’s application data
Verify the backup:
ls -la /tmp/jenkins-backup/ total 8 drwxrwxr-x. 3 user user 20 Sep 6 11:14 . drwxrwxrwt. 17 root root 4096 Sep 6 11:16 .. drwxrwsrwx. 12 user user 4096 Sep 6 11:14 jenkins
$ ls -la /tmp/jenkins-backup/ total 8 drwxrwxr-x. 3 user user 20 Sep 6 11:14 . drwxrwxrwt. 17 root root 4096 Sep 6 11:16 .. drwxrwsrwx. 12 user user 4096 Sep 6 11:14 jenkinsCopy to Clipboard Copied! Toggle word wrap Toggle overflow Use the
oc rsynctool to copy the data into the running pod:oc rsync /tmp/jenkins-backup/jenkins jenkins-1-37nux:/var/lib
$ oc rsync /tmp/jenkins-backup/jenkins jenkins-1-37nux:/var/libCopy to Clipboard Copied! Toggle word wrap Toggle overflow NoteDepending on the application, you may be required to restart the application.
Optionally, restart the application with new data:
oc delete pod jenkins-1-37nux
$ oc delete pod jenkins-1-37nuxCopy to Clipboard Copied! Toggle word wrap Toggle overflow Alternatively, you can scale down the deployment to 0, and then up again:
oc scale --replicas=0 dc/jenkins oc scale --replicas=1 dc/jenkins
$ oc scale --replicas=0 dc/jenkins $ oc scale --replicas=1 dc/jenkinsCopy to Clipboard Copied! Toggle word wrap Toggle overflow
2.3.1. Restoring a project Link kopierenLink in die Zwischenablage kopiert!
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.