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 30. Backup and Restore
30.1. Overview Copia collegamentoCollegamento copiato negli appunti!
In OpenShift Container Platform, you can back up (saving state to separate storage) and restore (recreating state from separate storage) at the cluster level. There is also some preliminary support for per-project backup. The full state of a cluster installation includes:
- etcd data on each master
- API objects
- registry storage
- volume storage
This topic does not cover how to back up and restore persistent storage, as those topics are left to the underlying storage provider. However, an example of how to perform a generic backup of application data is provided.
This topic only provides a generic way of backing up applications and the OpenShift Container Platform cluster. It can not take into account custom requirements. Therefore, you should create a full backup and restore procedure. To prevent data loss, necessary precautions should be taken.
30.2. Prerequisites Copia collegamentoCollegamento copiato negli appunti!
Because the restore procedure involves a complete reinstallation, save all the files used in the initial installation. This may include:
- ~/.config/openshift/installer.cfg.yml (from the Quick Installation method)
- Ansible playbooks and inventory files (from the Advanced Installation method)
- /etc/yum.repos.d/ose.repo (from the Disconnected Installation method)
- Backup the procedures for post-installation steps. Some installations may involve steps that are not included in the installer. This may include changes to the services outside of the control of OpenShift Container Platform or the installation of extra services like monitoring agents. Additional configuration that is not supported yet by the advanced installer might also be affected, for example when using multiple authentication providers.
Install packages that provide various utility commands:
yum install etcd
# yum install etcd
Copy to Clipboard Copied! Toggle word wrap Toggle overflow If using a container-based installation, pull the etcd image instead:
docker pull rhel7/etcd
# docker pull rhel7/etcd
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
Note the location of the etcd data directory (or $ETCD_DATA_DIR
in the following sections), which depends on how etcd is deployed.
Deployment Type | Description | Data Directory |
---|---|---|
separate etcd | etcd runs as a separate service, either co-located on master nodes or on separate nodes. | /var/lib/etcd |
embedded etcd | etcd runs as part of the master service. | /var/lib/origin/openshift.local.etcd |
30.3. Cluster Backup Copia collegamentoCollegamento copiato negli appunti!
30.3.1. Master Backup Copia collegamentoCollegamento copiato negli appunti!
You must perform the following step on each master node.
Create a backup of the master host configuration files:
MYBACKUPDIR=/backup/$(hostname)/$(date +%Y%m%d) sudo mkdir -p ${MYBACKUPDIR}/etc/sysconfig sudo cp -aR /etc/origin ${MYBACKUPDIR}/etc sudo cp -aR /etc/sysconfig/atomic-* ${MYBACKUPDIR}/etc/sysconfig/
$ MYBACKUPDIR=/backup/$(hostname)/$(date +%Y%m%d) $ sudo mkdir -p ${MYBACKUPDIR}/etc/sysconfig $ sudo cp -aR /etc/origin ${MYBACKUPDIR}/etc $ sudo cp -aR /etc/sysconfig/atomic-* ${MYBACKUPDIR}/etc/sysconfig/
Copy to Clipboard Copied! Toggle word wrap Toggle overflow If etcd is running on more than one host, stop it on each host:
sudo systemctl stop etcd
# sudo systemctl stop etcd
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Although this step is not strictly necessary, doing so ensures that the etcd data is fully synchronized.
Create an etcd backup:
etcdctl backup \ --data-dir $ETCD_DATA_DIR \ --backup-dir $ETCD_DATA_DIR.bak
# etcdctl backup \ --data-dir $ETCD_DATA_DIR \ --backup-dir $ETCD_DATA_DIR.bak
Copy to Clipboard Copied! Toggle word wrap Toggle overflow NoteIf etcd is running on more than one host, the various instances regularly synchronize their data, so creating a backup for one of them is sufficient.
NoteFor a container-based installation, you must use
docker exec
to run etcdctl inside the container.Copy the db file over to the backup you created:
cp "$ETCD_DATA_DIR"/member/snap/db "$ETCD_DATA_DIR.bak"/member/snap/db
$ cp "$ETCD_DATA_DIR"/member/snap/db "$ETCD_DATA_DIR.bak"/member/snap/db
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
30.4. Cluster Restore for Single-member etcd Clusters Copia collegamentoCollegamento copiato negli appunti!
To restore the cluster:
Reinstall OpenShift Container Platform.
This should be done in the same way that OpenShift Container Platform was previously installed.
- Run all necessary post-installation steps.
Restore the certificates and keys, on each master:
cd /etc/origin/master tar xvf /tmp/certs-and-keys-$(hostname).tar
# cd /etc/origin/master # tar xvf /tmp/certs-and-keys-$(hostname).tar
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Restore from the etcd backup:
mv $ETCD_DATA_DIR $ETCD_DATA_DIR.orig cp -Rp $ETCD_DATA_DIR.bak $ETCD_DATA_DIR chcon -R --reference $ETCD_DATA_DIR.orig $ETCD_DATA_DIR chown -R etcd:etcd $ETCD_DATA_DIR
# mv $ETCD_DATA_DIR $ETCD_DATA_DIR.orig # cp -Rp $ETCD_DATA_DIR.bak $ETCD_DATA_DIR # chcon -R --reference $ETCD_DATA_DIR.orig $ETCD_DATA_DIR # chown -R etcd:etcd $ETCD_DATA_DIR
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Create the new single node cluster using etcd’s
--force-new-cluster
option. You can do this using the values from /etc/etcd/etcd.conf, or you can temporarily modify the systemd unit file and start the service normally.To do so, edit the /usr/lib/systemd/system/etcd.service file, and add
--force-new-cluster
:sed -i '/ExecStart/s/"$/ --force-new-cluster"/' /usr/lib/systemd/system/etcd.service systemctl show etcd.service --property ExecStart --no-pager
# sed -i '/ExecStart/s/"$/ --force-new-cluster"/' /usr/lib/systemd/system/etcd.service # systemctl show etcd.service --property ExecStart --no-pager ExecStart=/bin/bash -c "GOMAXPROCS=$(nproc) /usr/bin/etcd --force-new-cluster"
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Then, restart the etcd service:
systemctl daemon-reload systemctl start etcd
# systemctl daemon-reload # systemctl start etcd
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Verify the etcd service started correctly, then re-edit the /usr/lib/systemd/system/etcd.service file and remove the
--force-new-cluster
option:sed -i '/ExecStart/s/ --force-new-cluster//' /usr/lib/systemd/system/etcd.service systemctl show etcd.service --property ExecStart --no-pager
# sed -i '/ExecStart/s/ --force-new-cluster//' /usr/lib/systemd/system/etcd.service # systemctl show etcd.service --property ExecStart --no-pager ExecStart=/bin/bash -c "GOMAXPROCS=$(nproc) /usr/bin/etcd"
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Restart the etcd service, then verify the etcd cluster is running correctly and displays OpenShift Container Platform’s configuration:
systemctl daemon-reload systemctl restart etcd
# systemctl daemon-reload # systemctl restart etcd
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
30.5. Cluster Restore for Multiple-member etcd Clusters Copia collegamentoCollegamento copiato negli appunti!
When using a separate etcd cluster, you must first restore the etcd backup by creating a new, single node etcd cluster. If you run etcd as a stand-alone service on your master nodes, you can create the single node etcd cluster on a master node. If you use separate etcd with multiple members, you must then also add any additional etcd members to the etcd cluster one by one.
However, the details of the restoration process differ between embedded and external etcd. See the following section and follow the relevant steps before Bringing OpenShift Services Back Online.
30.5.1. Embedded etcd Copia collegamentoCollegamento copiato negli appunti!
Restore your etcd backup and configuration:
Run the following on the master with the embedded etcd:
ETCD_DIR=/var/lib/origin/openshift.local.etcd mv $ETCD_DIR /var/lib/etcd.orig cp -Rp /var/lib/origin/etcd-backup-<timestamp>/ $ETCD_DIR chcon -R --reference /var/lib/etcd.orig/ $ETCD_DIR chown -R etcd:etcd $ETCD_DIR
# ETCD_DIR=/var/lib/origin/openshift.local.etcd # mv $ETCD_DIR /var/lib/etcd.orig # cp -Rp /var/lib/origin/etcd-backup-<timestamp>/ $ETCD_DIR # chcon -R --reference /var/lib/etcd.orig/ $ETCD_DIR # chown -R etcd:etcd $ETCD_DIR
Copy to Clipboard Copied! Toggle word wrap Toggle overflow WarningThe
$ETCD_DIR
location differs between external and embedded etcd.Create the new, single node etcd cluster:
etcd -data-dir=/var/lib/origin/openshift.local.etcd \ -force-new-cluster
# etcd -data-dir=/var/lib/origin/openshift.local.etcd \ -force-new-cluster
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Verify etcd has started successfully by checking the output from the above command, which should look similar to the following near the end:
[...] 2016-06-24 12:14:45.644073 I | etcdserver: starting server... [version: 2.2.5, cluster version: 2.2] [...] 2016-06-24 12:14:46.834394 I | etcdserver: published {Name:default ClientURLs:[http://localhost:2379 http://localhost:4001]} to cluster 5580663a6e0002
[...] 2016-06-24 12:14:45.644073 I | etcdserver: starting server... [version: 2.2.5, cluster version: 2.2] [...] 2016-06-24 12:14:46.834394 I | etcdserver: published {Name:default ClientURLs:[http://localhost:2379 http://localhost:4001]} to cluster 5580663a6e0002
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Shut down the process by running the following from a separate terminal:
pkill etcd
# pkill etcd
Copy to Clipboard Copied! Toggle word wrap Toggle overflow - Continue to Bringing OpenShift Container Platform Services Back Online.
30.5.2. Separate etcd Copia collegamentoCollegamento copiato negli appunti!
Choose a system to be the initial etcd member, and restore its etcd backup and configuration:
Run the following on the etcd host:
ETCD_DIR=/var/lib/etcd/ mv $ETCD_DIR /var/lib/etcd.orig cp -Rp /var/lib/origin/etcd-backup-<timestamp>/ $ETCD_DIR chcon -R --reference /var/lib/etcd.orig/ $ETCD_DIR chown -R etcd:etcd $ETCD_DIR
# ETCD_DIR=/var/lib/etcd/ # mv $ETCD_DIR /var/lib/etcd.orig # cp -Rp /var/lib/origin/etcd-backup-<timestamp>/ $ETCD_DIR # chcon -R --reference /var/lib/etcd.orig/ $ETCD_DIR # chown -R etcd:etcd $ETCD_DIR
Copy to Clipboard Copied! Toggle word wrap Toggle overflow WarningThe
$ETCD_DIR
location differs between external and embedded etcd.- Restore your /etc/etcd/etcd.conf file from backup or .rpmsave.
Create the new single node cluster using etcd’s
--force-new-cluster
option. You can do this with a long complex command using the values from /etc/etcd/etcd.conf, or you can temporarily modify the systemd unit file and start the service normally.To do so, edit the /usr/lib/systemd/system/etcd.service file, and add
--force-new-cluster
:sed -i '/ExecStart/s/"$/ --force-new-cluster"/' /usr/lib/systemd/system/etcd.service systemctl show etcd.service --property ExecStart --no-pager
# sed -i '/ExecStart/s/"$/ --force-new-cluster"/' /usr/lib/systemd/system/etcd.service # systemctl show etcd.service --property ExecStart --no-pager ExecStart=/bin/bash -c "GOMAXPROCS=$(nproc) /usr/bin/etcd --force-new-cluster"
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Then restart the etcd service:
systemctl daemon-reload systemctl start etcd
# systemctl daemon-reload # systemctl start etcd
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Verify the etcd service started correctly, then re-edit the /usr/lib/systemd/system/etcd.service file and remove the
--force-new-cluster
option:sed -i '/ExecStart/s/ --force-new-cluster//' /usr/lib/systemd/system/etcd.service systemctl show etcd.service --property ExecStart --no-pager
# sed -i '/ExecStart/s/ --force-new-cluster//' /usr/lib/systemd/system/etcd.service # systemctl show etcd.service --property ExecStart --no-pager ExecStart=/bin/bash -c "GOMAXPROCS=$(nproc) /usr/bin/etcd"
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Restart the etcd service, then verify the etcd cluster is running correctly and displays OpenShift Container Platform’s configuration:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow - 1
- Ensure that you specify the URLs of only active etcd members in the
--peers
parameter value.
- If you have additional etcd members to add to your cluster, continue to Adding Additional etcd Members. Otherwise, if you only want a single node separate etcd cluster, continue to Bringing OpenShift Container Platform Services Back Online.
30.5.2.1. Adding Additional etcd Members Copia collegamentoCollegamento copiato negli appunti!
To add additional etcd members to the cluster, you must first adjust the default localhost peer in the peerURLs
value for the first member:
Get the member ID for the first member using the
member list
command:etcdctl --cert-file=/etc/etcd/peer.crt \ --key-file=/etc/etcd/peer.key \ --ca-file=/etc/etcd/ca.crt \ --peers="https://172.18.1.18:2379,https://172.18.9.202:2379,https://172.18.0.75:2379" \ member list
# etcdctl --cert-file=/etc/etcd/peer.crt \ --key-file=/etc/etcd/peer.key \ --ca-file=/etc/etcd/ca.crt \ --peers="https://172.18.1.18:2379,https://172.18.9.202:2379,https://172.18.0.75:2379" \
1 member list
Copy to Clipboard Copied! Toggle word wrap Toggle overflow - 1
- Ensure that you specify the URLs of only active etcd members in the
--peers
parameter value.
Update the value of
peerURLs
using theetcdctl member update
command by passing the member ID obtained from the previous step:etcdctl --cert-file=/etc/etcd/peer.crt \ --key-file=/etc/etcd/peer.key \ --ca-file=/etc/etcd/ca.crt \ --peers="https://172.18.1.18:2379,https://172.18.9.202:2379,https://172.18.0.75:2379" \ member update 511b7fb6cc0001 https://172.18.1.18:2380
# etcdctl --cert-file=/etc/etcd/peer.crt \ --key-file=/etc/etcd/peer.key \ --ca-file=/etc/etcd/ca.crt \ --peers="https://172.18.1.18:2379,https://172.18.9.202:2379,https://172.18.0.75:2379" \ member update 511b7fb6cc0001 https://172.18.1.18:2380
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Alternatively, you can use
curl
:Copy to Clipboard Copied! Toggle word wrap Toggle overflow -
Re-run the
member list
command and ensure the peer URLs no longer include localhost. Now, add each additional member to the cluster one at a time.
WarningEach member must be fully added and brought online one at a time. When adding each additional member to the cluster, the
peerURLs
list must be correct for that point in time, so it will grow by one for each member added. Theetcdctl member add
command will output the values that need to be set in the etcd.conf file as you add each member, as described in the following instructions.For each member, add it to the cluster using the values that can be found in that system’s etcd.conf file:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow - 1
- In this line,
10.3.9.222
is a label for the etcd member. You can specify the host name, IP address, or a simple name.
-
Using the environment variables provided in the output of the above
etcdctl member add
command, edit the /etc/etcd/etcd.conf file on the member system itself and ensure these settings match. Now start etcd on the new member:
rm -rf /var/lib/etcd/member systemctl enable etcd systemctl start etcd
# rm -rf /var/lib/etcd/member # systemctl enable etcd # systemctl start etcd
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Ensure the service starts correctly and the etcd cluster is now healthy:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow - Now repeat this process for the next member to add to the cluster.
- After all additional etcd members have been added, continue to Bringing OpenShift Container Platform Services Back Online.
30.6. Adding New etcd Hosts Copia collegamentoCollegamento copiato negli appunti!
In cases where etcd members have failed and you still have a quorum of etcd cluster members running, you can use the surviving members to add additional etcd members without downtime.
Suggested Cluster Size
Having a cluster with an odd number of etcd hosts can account for fault tolerance. Having an odd number of etcd hosts does not change the number needed for a quorum, but increases the tolerance for failure. For example, a cluster size of three members, quorum is two leaving a failure tolerance of one. This ensures the cluster will continue to operate if two of the members are healthy.
Having an in-production cluster of three etcd hosts is recommended.
The following presumes you have a backup of the /etc/etcd configuration for the etcd hosts.
- If the new etcd members will also be OpenShift Container Platform nodes, see Add the desired number of hosts to the cluster. The rest of this procedure presumes you have added just one host, but if adding multiple, perform all steps on each host.
Upgrade etcd and iptables on the surviving nodes:
yum update etcd iptables-services
# yum update etcd iptables-services
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Ensure version
etcd-2.3.7-4.el7.x86_64
or greater is installed, and that the same version is installed on each host.Install etcd and iptables on the new host
yum install etcd iptables-services
# yum install etcd iptables-services
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Ensure version
etcd-2.3.7-4.el7.x86_64
or greater is installed, and that the same version is installed on the new host.- Backup the etcd data store on surviving hosts before making any cluster configuration changes.
If replacing a failed etcd member, remove the failed member before adding the new member.
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Stop the etcd service on the failed etcd member:
systemctl stop etcd
# systemctl stop etcd
Copy to Clipboard Copied! Toggle word wrap Toggle overflow On the new host, add the appropriate iptables rules:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Generate the required certificates for the new host. On a surviving etcd host:
- Make a backup of the /etc/etcd/ca/ directory.
Set the variables and working directory for the certificates, ensuring to create the PREFIX directory if one has not been created:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Create the $PREFIX directory:
mkdir -p $PREFIX
$ mkdir -p $PREFIX
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Create the server.csr and server.crt certificates:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Create the peer.csr and peer.crt certificates:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Copy the etcd.conf and ca.crt files, and archive the contents of the directory:
cp etcd.conf ${PREFIX} cp ca.crt ${PREFIX} tar -czvf ${PREFIX}${CN}.tgz -C ${PREFIX} .
# cp etcd.conf ${PREFIX} # cp ca.crt ${PREFIX} # tar -czvf ${PREFIX}${CN}.tgz -C ${PREFIX} .
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Transfer the files to the new etcd hosts:
scp ${PREFIX}${CN}.tgz $CN:/etc/etcd/
# scp ${PREFIX}${CN}.tgz $CN:/etc/etcd/
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
While still on the surviving etcd host, add the new host to the cluster:
Add the new host to the cluster:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Copy the three environment variables in the etcdctl member add output. They will be used later.
On the new host, extract the copied configuration data and set the permissions:
tar -xf /etc/etcd/<NEW_ETCD_HOSTNAME>.tgz -C /etc/etcd/ --overwrite chown -R etcd:etcd /etc/etcd/*
# tar -xf /etc/etcd/<NEW_ETCD_HOSTNAME>.tgz -C /etc/etcd/ --overwrite # chown -R etcd:etcd /etc/etcd/*
Copy to Clipboard Copied! Toggle word wrap Toggle overflow On the new host, remove any etcd data:
rm -rf /var/lib/etcd/member chown -R etcd:etcd /var/lib/etcd
# rm -rf /var/lib/etcd/member # chown -R etcd:etcd /var/lib/etcd
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
On the new etcd host, update the etcd.conf file:
Replace the following with the values generated in the previous step:
- ETCD_NAME
- ETCD_INITIAL_CLUSTER
- ETCD_INITIAL_CLUSTER_STATE
Replace the IP address with the "NEW_ETCD" value for:
- ETCD_LISTEN_PEER_URLS
- ETCD_LISTEN_CLIENT_URLS
- ETCD_INITIAL_ADVERTISE_PEER_URLS
- ETCD_ADVERTISE_CLIENT_URLS
- For replacing failed members, replace the failed hosts with the new hosts.
-
To ensure the etcd configuration does not use the failed host when the etcd service is restarted, modify the etcd.conf file on all remaining etcd hosts and remove the failed host in the value for the
ETCD_INITIAL_CLUSTER
variable. -
On the node that hosts the installation files, update the
[etcd]
hosts group in the /etc/ansible/hosts inventory file. Remove the old etcd hosts and add the new ones. Start etcd on the new host:
systemctl enable etcd --now
# systemctl enable etcd --now
Copy to Clipboard Copied! Toggle word wrap Toggle overflow To verify that the new member has been added successfully:
etcdctl -C https://${ETCD_CA_HOST}:2379 --ca-file=/etc/etcd/ca.crt \ --cert-file=/etc/etcd/peer.crt \ --key-file=/etc/etcd/peer.key cluster-health
etcdctl -C https://${ETCD_CA_HOST}:2379 --ca-file=/etc/etcd/ca.crt \ --cert-file=/etc/etcd/peer.crt \ --key-file=/etc/etcd/peer.key cluster-health
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Update the master configuration on all masters to point to the new etcd host
- On every master in the cluster, edit /etc/origin/master/master-config.yaml
- Find the etcdClientInfo section.
- Add the new etcd host to the urls list.
- If a failed etcd host was replaced, remove it from the list.
Restart the master API service.
On a single master cluster installation:
systemctl restart atomic-openshift-master
# systemctl restart atomic-openshift-master
Copy to Clipboard Copied! Toggle word wrap Toggle overflow On a multi-master cluster installation, on each master:
systemctl restart atomic-openshift-master-api
# systemctl restart atomic-openshift-master-api
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
The procedure to add an etcd member is complete.
30.7. Bringing OpenShift Container Platform Services Back Online Copia collegamentoCollegamento copiato negli appunti!
On each OpenShift Container Platform master, restore your master and node configuration from backup and enable and restart all relevant services.
On the master in a single master cluster:
On each master in a multi-master cluster:
On each OpenShift Container Platform node, restore your node-config.yaml file from backup and enable and restart the atomic-openshift-node service:
cp /etc/origin/node/node-config.yaml.<timestamp> /etc/origin/node/node-config.yaml systemctl enable atomic-openshift-node systemctl start atomic-openshift-node
# cp /etc/origin/node/node-config.yaml.<timestamp> /etc/origin/node/node-config.yaml
# systemctl enable atomic-openshift-node
# systemctl start atomic-openshift-node
Your OpenShift Container Platform cluster should now be back online.
30.8. Project Backup Copia collegamentoCollegamento copiato negli appunti!
A future release of OpenShift Container Platform will feature specific support for per-project back up and restore.
For now, to back up API objects at the project level, use oc export
for each object to be saved. For example, to save the deployment configuration frontend
in YAML format:
oc export dc frontend -o yaml > dc-frontend.yaml
$ oc export dc frontend -o yaml > dc-frontend.yaml
To back up all of the project (with the exception of cluster objects like namespaces and projects):
oc export all -o yaml > project.yaml
$ oc export all -o yaml > project.yaml
30.8.1. Role Bindings Copia collegamentoCollegamento copiato negli appunti!
Sometimes custom policy role bindings are used in a project. For example, a project administrator can give another user a certain role in the project and grant that user project access.
These role bindings can be exported:
oc get rolebindings -o yaml --export=true > rolebindings.yaml
$ oc get rolebindings -o yaml --export=true > rolebindings.yaml
30.8.2. Service Accounts Copia collegamentoCollegamento copiato negli appunti!
If custom service accounts are created in a project, these need to be exported:
oc get serviceaccount -o yaml --export=true > serviceaccount.yaml
$ oc get serviceaccount -o yaml --export=true > serviceaccount.yaml
30.8.3. Secrets Copia collegamentoCollegamento copiato negli appunti!
Custom secrets like source control management secrets (SSH Public Keys, Username/Password) should be exported if they are used:
oc get secret -o yaml --export=true > secret.yaml
$ oc get secret -o yaml --export=true > secret.yaml
30.8.4. Persistent Volume Claims Copia collegamentoCollegamento copiato negli appunti!
If the an application within a project uses a persistent volume through a persistent volume claim (PVC), these should be backed up:
oc get pvc -o yaml --export=true > pvc.yaml
$ oc get pvc -o yaml --export=true > pvc.yaml
30.9. Project Restore Copia collegamentoCollegamento copiato negli appunti!
To restore a project, recreate the project and recreate all all of the objects that were exported during the backup:
Some resources can fail to be created (for example, pods and default service accounts).
30.10. Application Data Backup Copia collegamentoCollegamento copiato negli appunti!
In many cases, application data can be backed up using the oc rsync
command, assuming rsync
is installed within the container image. The Red Hat rhel7 base image does contain 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/import procedures for database systems.
Other means of backup may exist depending on the type of the persistent volume (for example, Cinder, NFS, Gluster, or others).
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
.
Example of Backing up a Jenkins Deployment’s Application Data
Get the application data
mountPath
from thedeploymentconfig
:oc get dc/jenkins -o jsonpath='{ .spec.template.spec.containers[?(@.name=="jenkins")].volumeMounts[?(@.name=="jenkins-data")].mountPath }'
$ oc get dc/jenkins -o jsonpath='{ .spec.template.spec.containers[?(@.name=="jenkins")].volumeMounts[?(@.name=="jenkins-data")].mountPath }' /var/lib/jenkins
Copy 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 }'
$ oc get pod --selector=deploymentconfig=jenkins -o jsonpath='{ .metadata.name }' jenkins-1-37nux
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Use the
oc rsync
command 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
This type of application data backup can only be performed while an application pod is currently running.
30.11. Application Data Restore Copia collegamentoCollegamento copiato negli appunti!
The process for restoring application data is similar to the application backup procedure using the oc rsync
tool. The same restrictions apply and the process of restoring application data requires a persistent volume.
Example of Restoring a Jenkins Deployment’s Application Data
Verify the backup:
ls -la /tmp/jenkins-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
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Use the
oc rsync
tool 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/lib
Copy to Clipboard Copied! Toggle word wrap Toggle overflow NoteDepending on the application, you may be required to restart the application.
Restart the application with new data (optional):
oc delete pod jenkins-1-37nux
$ oc delete pod jenkins-1-37nux
Copy 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/jenkins
Copy to Clipboard Copied! Toggle word wrap Toggle overflow