Backup and restore
Backup and restore the Red Hat build of MicroShift database
Abstract
Chapter 1. Backing up and restoring {microshift-short} data Copy linkLink copied to clipboard!
To back up and restore MicroShift data manually, you can use the backup and restore procedures for the database on all supported systems. For application data, you must define your own backup and restore steps.
Only MicroShift data is backed up with the following procedures. Application data is not included.
-
On
rpm-ostreesystems, MicroShift automatically creates a backup on every start. These automatic backups are deleted and replaced with the latest backup each time the system restarts. -
If you are using an
rpm-ostreesystem, the data is automatically restored after greenboot rolls the system back. This data restoration ensures that the database matches the software running on the host after the rollback is completed. - On other system types, you must back up and restore data manually.
1.1. Stopping the MicroShift service Copy linkLink copied to clipboard!
To stop the MicroShift service, you can run systemctl stop microshift. You can also stop any deployed workloads by running systemctl stop kubepods.slice.
Prerequisites
- The MicroShift service is running.
Procedure
Enter the following command to stop the MicroShift service:
sudo systemctl stop microshift
$ sudo systemctl stop microshiftCopy to Clipboard Copied! Toggle word wrap Toggle overflow Workloads deployed on MicroShift might continue running even after the MicroShift service has been stopped. Enter the following command to display running workloads:
sudo crictl ps -a
$ sudo crictl ps -aCopy to Clipboard Copied! Toggle word wrap Toggle overflow Enter the following commands to stop the deployed workloads:
sudo systemctl stop kubepods.slice
$ sudo systemctl stop kubepods.sliceCopy to Clipboard Copied! Toggle word wrap Toggle overflow
1.2. Backing up MicroShift data manually Copy linkLink copied to clipboard!
To back up Red Hat build of MicroShift data manually, you can run microshift backup with a full path to the backup location. Stop the service first and use the entire path for the output file or directory.
You can back up MicroShift data manually at any time. Back up your data before system updates to preserve it for use if an update fails or for other system trouble. You can use the /var/lib/microshift-backups for manually backing up and restoring data by specifying it in each command.
Prerequisites
- You have root access to the host.
- MicroShift is stopped.
Procedure
Manually create a backup by using the parent directory and specifying a name, such as
/var/lib/microshift-backups/<my_manual_backup>, by running the following command:sudo microshift backup /var/lib/microshift-backups/_<manual_backup>_
$ sudo microshift backup /var/lib/microshift-backups/_<manual_backup>_Copy to Clipboard Copied! Toggle word wrap Toggle overflow For
<manual_backup>, specify the backup name that you want to use.Example output
??? I1017 07:38:16.770506 5900 data_manager.go:92] "Copying data to backup directory" storage="/var/lib/microshift-backups" name="test" data="/var/lib/microshift" ??? I1017 07:38:16.770713 5900 data_manager.go:227] "Starting copy" cmd="/bin/cp --verbose --recursive --preserve --reflink=auto /var/lib/microshift /var/lib/microshift-backups/test" ??? I1017 07:38:16.776162 5900 data_manager.go:241] "Finished copy" cmd="/bin/cp --verbose --recursive --preserve --reflink=auto /var/lib/microshift /var/lib/microshift-backups/test" ??? I1017 07:38:16.776256 5900 data_manager.go:125] "Copied data to backup directory" backup="/var/lib/microshift-backups/test" data="/var/lib/microshift"
??? I1017 07:38:16.770506 5900 data_manager.go:92] "Copying data to backup directory" storage="/var/lib/microshift-backups" name="test" data="/var/lib/microshift" ??? I1017 07:38:16.770713 5900 data_manager.go:227] "Starting copy" cmd="/bin/cp --verbose --recursive --preserve --reflink=auto /var/lib/microshift /var/lib/microshift-backups/test" ??? I1017 07:38:16.776162 5900 data_manager.go:241] "Finished copy" cmd="/bin/cp --verbose --recursive --preserve --reflink=auto /var/lib/microshift /var/lib/microshift-backups/test" ??? I1017 07:38:16.776256 5900 data_manager.go:125] "Copied data to backup directory" backup="/var/lib/microshift-backups/test" data="/var/lib/microshift"Copy to Clipboard Copied! Toggle word wrap Toggle overflow
Optional: Manually create a backup in a specific parent directory with a custom name by running the following command:
sudo microshift backup /mnt/<other_backups_location>/<another_manual_backup>
$ sudo microshift backup /mnt/<other_backups_location>/<another_manual_backup>Copy to Clipboard Copied! Toggle word wrap Toggle overflow Replace
<other_backups_location>with the directory you want to use and<my_manual_backup>with the backup name you want to use.
Verification
-
You can verify that the backup exists by viewing the data in the directory you chose. For example,
/var/lib/microshift-backups/<manual_backup>/or/mnt/<other_backups_location>/<another_manual_backup>.
1.3. Restoring MicroShift data backups manually Copy linkLink copied to clipboard!
To restore Red Hat build of MicroShift data after an update or data loss, you can run microshift restore with the full path to the backup. Backups can be restored after updates, or after other system events that remove or damage required data. When you restore a backup, you must use the entire file path.
On an rpm-ostree system, MicroShift backs up and restores data automatically.
Prerequisites
- Root access to the host.
- Full path of the data backup file.
- The MicroShift service is stopped.
Procedure
Manually restore MicroShift data by using the full file path of the backup you want to restore by running the following command:
sudo microshift restore /var/lib/microshift-backups/_<manual_backup>_
$ sudo microshift restore /var/lib/microshift-backups/_<manual_backup>_Copy to Clipboard Copied! Toggle word wrap Toggle overflow For
<manual_backup>, specify the backup name that you want to use. Optionally, you can also restore automaticostreebackups using the full file path.Example output
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
Optional. Manually restore data from a customized directory by using the full file path of the backup. Run the following command:
sudo microshift restore /mnt/_<other_backups_location>_/_<another_manual_backup>_
$ sudo microshift restore /mnt/_<other_backups_location>_/_<another_manual_backup>_Copy to Clipboard Copied! Toggle word wrap Toggle overflow -
For
<other_backups_location>, specify the directory that you used. -
For
<another_manual_backup>, specify the backup name that you used when creating the backup you are restoring.
-
For
- Restart the host. Restarting the host enables all workloads and pods to restart.
Verification
Use the
oc get pods -Acommand to verify that the node is running, then check the restored data.oc get pods -A
$ oc get pods -ACopy to Clipboard Copied! Toggle word wrap Toggle overflow Example output
Copy to Clipboard Copied! Toggle word wrap Toggle overflow NoteThis example output shows a basic MicroShift installation. If you installed optional RPMs, the status of pods running those services is also expected in your output.
Chapter 2. Automated recovery from manual backups Copy linkLink copied to clipboard!
To automatically restore Red Hat build of MicroShift when it fails to start, you can configure automatic recovery from manual backups. Create backups in a single directory and configure restore to use the latest backup on failure.
2.1. Modifying backup and restore commands to automate data recovery Copy linkLink copied to clipboard!
The --auto-recovery option stores Red Hat build of MicroShift backups in one directory and selects the latest backup when you restore. You add the option to your backup and restore commands for 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 backupcommand, such as inmicroshift backup --auto-recovery PATH, a new backup is created in the PATH. -
By default,
microshift restore --auto-recovery PATHcreates a backup of the failed MicroShift data inPATH/failed. You can add the--dont-save-failedoption 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!
To create backups for Red Hat build of MicroShift automatic recovery, you can run microshift backup --auto-recovery with a directory path. The command then stores each backup in that directory so that the latest is available when you restore.
Creating backups requires stopping MicroShift. You must decide on 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>Copy to Clipboard Copied! Toggle word wrap Toggle overflow For
<path_of_directory>, specify the path of the directory that stores backups. For example,/var/lib/microshift-auto-recovery.NoteThe
--auto-recoveryoption modifies the interpretation of thePATHargument 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>Copy to Clipboard Copied! Toggle word wrap Toggle overflow -
For
<path_of_directory>, specify the path of the directory that stores backups. For example,/var/lib/microshift-auto-recovery.
-
For
2.3. Restoring backups using the auto-recovery feature Copy linkLink copied to clipboard!
To recover Red Hat build of MicroShift data after loss or damage, you can run the microshift restore --auto-recovery command with your backups directory, which restores the latest backup. 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>Copy to Clipboard Copied! Toggle word wrap Toggle overflow For
<path_of_directory>, specify the path of the directory that stores backups. For example,/var/lib/microshift-auto-recovery.Note-
The
--auto-recoveryoption 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-failedoption disables the backing up of failed MicroShift data.
Example output
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Important-
The
restorecommand 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.
-
The
Restart MicroShift by running the following command:
sudo systemctl restart microshift
$ sudo systemctl restart microshiftCopy 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 -ACopy to Clipboard Copied! Toggle word wrap Toggle overflow Example output
Copy to Clipboard Copied! Toggle word wrap Toggle overflow NoteThis example output shows a basic MicroShift installation. If you installed optional RPMs, the status of pods running those services is also expected in your output.
2.3.1. Using automatic recovery in RPM systems Copy linkLink copied to clipboard!
To use automatic recovery for Red Hat build of MicroShift on RPM systems, you can create the 10-auto-recovery.conf file, the microshift-auto-recovery.service unit, and the microshift-auto-recovery script. Systemd runs the recovery service when the Red Hat build of MicroShift service does not start, and the script restores the latest backup.
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
microshiftsystemd 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.dCopy to Clipboard Copied! Toggle word wrap Toggle overflow To instruct
systemdto runmicroshift-auto-recovery.servicewhen themicroshift.servicefails, create the10-auto-recovery.conffile 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 EOFCopy to Clipboard Copied! Toggle word wrap Toggle overflow -
For
StartLimitIntervalSec, specify a value greater than the default10sfor slower systems. A value that is too low can result in systemd never marking themicroshiftsystemd service as failed, which means that theOnFailure=service does not get triggered.
-
For
Create the
microshift-auto-recovery.servicefile by running the following command:Copy to Clipboard Copied! Toggle word wrap Toggle overflow Create the
microshift-auto-recoveryscript 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-recoveryCopy to Clipboard Copied! Toggle word wrap Toggle overflow Reload the system configuration by running the following command:
sudo systemctl daemon-reload
$ sudo systemctl daemon-reloadCopy to Clipboard Copied! Toggle word wrap Toggle overflow
2.3.2. Using automatic recovery with RHEL for Edge Copy linkLink copied to clipboard!
To use automatic recovery for Red Hat build of MicroShift on RHEL for Edge systems, you can add the auto-recovery systemd service, 10-auto-recovery.conf, and the microshift-auto-recovery script to your blueprint. Use blueprint customizations so the image includes these files and recovery runs automatically.
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-clitool.
Procedure
-
Optional: Because the
composer-clican only create files in the/etcdirectory, 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!
Image mode for RHEL is a Technology Preview feature only. Technology Preview features are not supported with Red Hat production service level agreements (SLAs) and might not be functionally complete. Red Hat does not recommend using them in production. These features provide early access to upcoming product features, enabling customers to test functionality and provide feedback during the development process.
For more information about the support scope of Red Hat Technology Preview features, see Technology Preview Features Support Scope.
To use automatic recovery for Red Hat build of MicroShift on RHEL image-based systems, you can embed the 10-auto-recovery.conf and microshift-auto-recovery.service files in your Containerfile and rebuild the bootc image.
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.confandmicroshift-auto-recovery.servicefiles as explained in the "Using auto-recovery in RPM systems" section.ImportantThe location of the
10-auto-recovery.confandmicroshift-auto-recovery.servicefiles 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-recoveryscript 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-recoveryCopy 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
rhocpandfast-datapathrepositories 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
--authfileargument is required to pull the baserhel-bootc:9.4image from theregistry.redhat.ioregistry. -
The build
USER_PASSWDargument 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 GBCopy to Clipboard Copied! Toggle word wrap Toggle overflow