Red Hat Certified Engineer RHCE · Free Practice Question Hard

Question 2

Your organization relies on a MySQL database for critical applications, and data backup is essential for disaster recovery. You are tasked with automating daily MySQL backups using Ansible, ensuring backups are securely stored and old backups are deleted after 7 days to conserve disk space. How would you achieve this using Ansible?

  • A
  • B

    This is a performance based question and not multiple choice.  Therefore the answer is in #1.  If you require additional explanation, please ask your question in the Q&A section.

Reveal correct answer

Correct answer: A

A.

This Ansible playbook automates daily MySQL database backups and cleanup of old backup files to ensure effective disaster recovery and optimize disk space. It first creates a designated backup directory with the required permissions if it doesn’t already exist. Then, it uses the mysqldump utility to back up all databases, saving the files with a timestamped name. Finally, it removes backup files older than 7 days from the backup directory to prevent storage overload. This automated solution ensures data is consistently backed up and old files are systematically purged, reducing administrative overhead.

Line-by-Line Explanation

Provides a descriptive name for the playbook to indicate its purpose.

Specifies that the playbook will target the group of hosts labeled db_servers.

Defines the tasks that will be executed in this playbook.

Describes the task to ensure a directory exists for storing backups.

Uses the file module to manage the state of files or directories.

Specifies the path for the backup directory.

Ensures that the path is a directory.

Sets the permissions of the directory to allow appropriate access.

Describes the task to back up all MySQL databases.

Uses the shell module to execute the mysqldump command.

Runs the mysqldump utility to export all databases to a file named with the current date.

Defines arguments for the task.

Ensures the task only runs if the backup file doesn’t already exist.

Describes the task to delete old backups from the directory.

Uses the find module to locate and remove files.

Specifies the directory to search for files.

Searches for files matching the .sql pattern (database backups).

Targets files older than 7 days.

Ensures the search includes subdirectories.

Deletes the files that match the criteria.

Discussion

Think the marked answer is wrong, or have a better explanation? Share it below — comments appear after review.

You must be logged in to post a comment.

Preparing For

Your Certification?

255+ certifications
Detailed explanations
Free PDF samples

Has All The Questions You Need