Chapter 2. Automated recovery from manual backups
You can automatically restore data from manual backups when MicroShift fails to start by configuring automatic recovery.
2.1. Modifying backup and restore commands to automate data recovery Copy linkLink copied to clipboard!
Use automatic recovery options to store all of your backups in a single directory, then automatically select the latest one to restore. Modifying existing backup
and restore
commands enables you to set up automatic recovery.
The --auto-recovery
option treats the PATH
argument as a path to a directory that holds all the backups for automated recovery, and not just as a path to a particular backup file. You can use the --auto-recovery
option with both backup
and restore
commands.
-
For example, if you use the automatic recovery option with
restore
, such as inmicroshift restore --auto-recovery PATH
, running the modified command automatically selects and restores the most recent backup. -
If you use the same option in the
microshift backup
command, such as inmicroshift backup --auto-recovery PATH
, a new backup is created in the PATH. -
By default,
microshift restore --auto-recovery PATH
creates a backup of the failed MicroShift data inPATH/failed
. You can add the--dont-save-failed
option to disable the creation of failed backup data.
You can only use the --dont-save-failed
option with the restore
command.
2.2. Creating backups using the auto-recovery feature Copy linkLink copied to clipboard!
Use the following procedure to create backups using automatic recovery options.
Creating backups require stopping MicroShift, so you must determine the best time to stop MicroShift.
Prerequisites
- You stopped MicroShift.
Procedure
Create and store backups in the directory you choose by running the following command:
sudo microshift backup --auto-recovery <path_of_directory>
$ sudo microshift backup --auto-recovery <path_of_directory>
1 Copy to Clipboard Copied! Toggle word wrap Toggle overflow - 1
- Replace
<path_of_directory>
with the path of the directory that stores backups. For example,/var/lib/microshift-auto-recovery
.
NoteThe
--auto-recovery
option modifies the interpretation of thePATH
argument from the final backup path to a directory that holds all of the backups for automated recovery.Example output
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
Verification
Verify that the backup you created exists in your customized storage directory by running the following command:
sudo ls -la <path_of_directory>
$ sudo ls -la <path_of_directory>
1 Copy to Clipboard Copied! Toggle word wrap Toggle overflow - 1
- Replace
<path_of_directory>
with the path of the directory that stores backups. For example,/var/lib/microshift-auto-recovery
.
2.3. Restoring backups using the auto-recovery feature Copy linkLink copied to clipboard!
You can restore backups after system events that remove or damage required data. Use the following procedure to restore backups using automatic recovery. Automatic recovery selects the most recent backup and restores it. Previously restored backups that used automatic recovery are moved to your PATH/restored
directory.
Prerequisites
- You have stopped MicroShift.
Procedure
Restore the latest backup from your backups directory by running the following command:
sudo microshift restore --auto-recovery <path_of_directory>
$ sudo microshift restore --auto-recovery <path_of_directory>
1 Copy to Clipboard Copied! Toggle word wrap Toggle overflow - 1
- Replace
<path_of_directory>
with the path of the directory that stores backups. For example,/var/lib/microshift-auto-recovery
.
Note-
The
--auto-recovery
option copies the MicroShift data to/var/lib/microshift-auto-recovery/failed/
for later investigation, selects the most recent backup, and restores it. -
The
--dont-save-failed
option disables the backing up of failed MicroShift data.
Example output
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Important-
The
restore
command does not restart MicroShift after restoration. When you execute this command, MicroShift service has already failed or you stopped it. - MicroShift does not monitor the disk space of any filesystem. You must ensure that your automation handles old backup removal. For example, you can add this process to the auto-recovery service or add another service that runs periodically.
Restart MicroShift by running the following command:
sudo systemctl restart microshift
$ sudo systemctl restart microshift
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
Verification
Verify that MicroShift has started successfully by running the following command:
oc get pods -A
$ oc get pods -A
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Example output
Copy to Clipboard Copied! Toggle word wrap Toggle overflow NoteThis example output shows basic MicroShift. If you have installed optional RPMs, the status of pods running those services is also expected to be shown in your output.
2.3.1. Using automatic recovery in RPM systems Copy linkLink copied to clipboard!
When MicroShift enters a failed state, the systemd service starts the microshift-auto-recovery.service
unit. This unit executes the auto-recovery
restore process.
As a use case, consider the following example situation in which you want to automate the automatic recovery process for RPM systems that use the systemd service.
Procedure
Create a directory for the
microshift
systemd service by running the following command:sudo mkdir -p /usr/lib/systemd/system/microshift.service.d
$ sudo mkdir -p /usr/lib/systemd/system/microshift.service.d
Copy to Clipboard Copied! Toggle word wrap Toggle overflow To instruct
systemd
to runmicroshift-auto-recovery.service
when themicroshift.service
fails, create the10-auto-recovery.conf
file by running the following command:sudo tee /usr/lib/systemd/system/microshift.service.d/10-auto-recovery.conf > /dev/null <<'EOF' [Unit] OnFailure=microshift-auto-recovery.service StartLimitIntervalSec=25s EOF
$ sudo tee /usr/lib/systemd/system/microshift.service.d/10-auto-recovery.conf > /dev/null <<'EOF' [Unit] OnFailure=microshift-auto-recovery.service StartLimitIntervalSec=25s
1 EOF
Copy to Clipboard Copied! Toggle word wrap Toggle overflow - 1
- Increase the
StartLimitInterval
value from the default10s
to a larger value for slower systems. A value that is too low can result in systemd never marking themicroshift
systemd service as failed, which means that theOnFailure=
service does not get triggered.
Create the
microshift-auto-recovery.service
file by running the following command:Copy to Clipboard Copied! Toggle word wrap Toggle overflow Create the
microshift-auto-recovery
script by running the following command:Copy to Clipboard Copied! Toggle word wrap Toggle overflow Make the script executable by running the following command:
sudo chmod +x /usr/bin/microshift-auto-recovery
$ sudo chmod +x /usr/bin/microshift-auto-recovery
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Reload the system configuration by running the following command:
sudo systemctl daemon-reload
$ sudo systemctl daemon-reload
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
2.3.2. Using automatic recovery with RHEL for Edge Copy linkLink copied to clipboard!
As a use case, consider the following example situation in which you want to automate the auto-recovery
process for Red Hat Enterprise Linux for Edge (RHEL for Edge) systems that use systemd in the blueprint file.
You must include the entire auto-recovery
process for RHEL for Edge systems that use systemd
in the blueprint file.
Prerequisites
- You installed Podman.
-
You installed the command-line
composer-cli
tool.
Procedure
-
Optional: Because the
composer-cli
can only create files in the/etc
directory, package your files into an RPM that you include the blueprint. Use the following example to create your blueprint file:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow - For the next steps, see Preparing for image building.
2.3.3. Using automatic recovery in image mode for RHEL systems Copy linkLink copied to clipboard!
As a use case, consider the following example situation in which you want to automate the auto-recovery
process for image mode for Red Hat Enterprise Linux (RHEL) systems that use the systemd service.
You must include the entire auto-recovery
process for image mode for RHEL systems that use systemd
in the container file.
Prerequisites
- You created a Containerfile as instructed in Building the bootc image.
You created the
10-auto-recovery.conf
andmicroshift-auto-recovery.service
files as explained in the "Using auto-recovery in RPM systems" section.ImportantThe location of the
10-auto-recovery.conf
andmicroshift-auto-recovery.service
must be relative to the Containerfile.For example, if the path to the Containerfile is
/home/microshift/my-build/Containerfile
, the systemd files need to be adjacent for proper embedding. The following paths are correct for this example:-
/home/microshift/my-build/auto-rec/10-auto-recovery.conf
-
/home/microshift/my-build/auto-rec/microshift-auto-recovery.service
-
/home/microshift/my-build/auto-rec/microshift-auto-recovery
-
-
You created the
microshift-auto-recovery
script as explained in the "Using auto-recovery in RPM systems" section.
Procedure
Use the following example snippet to update the container file that you use to prepare the image mode for RHEL image.
RUN mkdir -p /usr/lib/systemd/system/microshift.service.d COPY ./auto-rec/10-auto-recovery.conf /usr/lib/systemd/system/microshift.service.d/10-auto-recovery.conf COPY ./auto-rec/microshift-auto-recovery.service /usr/lib/systemd/system/ COPY ./auto-rec/microshift-auto-recovery /usr/bin/ RUN chmod +x /usr/bin/microshift-auto-recovery
RUN mkdir -p /usr/lib/systemd/system/microshift.service.d COPY ./auto-rec/10-auto-recovery.conf /usr/lib/systemd/system/microshift.service.d/10-auto-recovery.conf COPY ./auto-rec/microshift-auto-recovery.service /usr/lib/systemd/system/ COPY ./auto-rec/microshift-auto-recovery /usr/bin/ RUN chmod +x /usr/bin/microshift-auto-recovery
Copy to Clipboard Copied! Toggle word wrap Toggle overflow ImportantPodman uses the host subscription information and repositories inside the container when building the container image. If the
rhocp
andfast-datapath
repositories are not available on the host, the build fails.Rebuild your local bootc image by running the following image build command:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow NoteSecrets are used during the image build in the following ways:
-
The podman
--authfile
argument is required to pull the baserhel-bootc:9.4
image from theregistry.redhat.io
registry. -
The build
USER_PASSWD
argument is used to set a password for theredhat user
.
-
The podman
Verification
Verify that the local bootc image was created by running the following command:
sudo podman images "${IMAGE_NAME}"
$ sudo podman images "${IMAGE_NAME}"
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Example output
REPOSITORY TAG IMAGE ID CREATED SIZE localhost/microshift-4.18-bootc latest 193425283c00 2 minutes ago 2.31 GB
REPOSITORY TAG IMAGE ID CREATED SIZE localhost/microshift-4.18-bootc latest 193425283c00 2 minutes ago 2.31 GB
Copy to Clipboard Copied! Toggle word wrap Toggle overflow