-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Creating a unmount_operation with safety checks for nasbackup.sh #12133
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: 4.22
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -153,8 +153,7 @@ backup_running_vm() { | |||||||||||||||||||||||||||||||||||
| virsh -c qemu:///system domjobinfo $VM --completed | ||||||||||||||||||||||||||||||||||||
| du -sb $dest | cut -f1 | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| umount $mount_point | ||||||||||||||||||||||||||||||||||||
| rmdir $mount_point | ||||||||||||||||||||||||||||||||||||
| umount_operation | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| backup_stopped_vm() { | ||||||||||||||||||||||||||||||||||||
|
|
@@ -183,6 +182,8 @@ backup_stopped_vm() { | |||||||||||||||||||||||||||||||||||
| sync | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| ls -l --numeric-uid-gid $dest | awk '{print $5}' | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| umount_operation | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| delete_backup() { | ||||||||||||||||||||||||||||||||||||
|
|
@@ -218,6 +219,34 @@ mount_operation() { | |||||||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| umount_operation() { | ||||||||||||||||||||||||||||||||||||
| elapsed=0 | ||||||||||||||||||||||||||||||||||||
| while fuser -m "$mount_point" >/dev/null 2>&1 && (( elapsed < 10 )); do | ||||||||||||||||||||||||||||||||||||
| sleep 1 | ||||||||||||||||||||||||||||||||||||
| elapsed=$((elapsed + 1)) | ||||||||||||||||||||||||||||||||||||
| done | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| # Check if timeout was reached | ||||||||||||||||||||||||||||||||||||
| if (( elapsed >= 10 )); then | ||||||||||||||||||||||||||||||||||||
|
Comment on lines
+223
to
+230
|
||||||||||||||||||||||||||||||||||||
| elapsed=0 | |
| while fuser -m "$mount_point" >/dev/null 2>&1 && (( elapsed < 10 )); do | |
| sleep 1 | |
| elapsed=$((elapsed + 1)) | |
| done | |
| # Check if timeout was reached | |
| if (( elapsed >= 10 )); then | |
| local timeout=10 | |
| elapsed=0 | |
| while fuser -m "$mount_point" >/dev/null 2>&1 && (( elapsed < timeout )); do | |
| sleep 1 | |
| elapsed=$((elapsed + 1)) | |
| done | |
| # Check if timeout was reached | |
| if (( elapsed >= timeout )); then |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not sure if we should exit on error. Am I reading this wrong?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The script was set to exit on error at the start of the file, but when unmounting fails it does not give any meaningful error output, capturing the output allows to generate a log and an error message that is verbose and allows the administrator to know there is an issue.
Also when umount fails and stops the script, the backup is reported as failed and can't be deleted from Cloudstack as in the DB of Cloudstack this backup is failed and not created. Removing the exit on error and instead logging allows the backup to be marked as success.
In most of the cases, the umount should not fail, as we are waiting before for the fs to be synced. But in the case it does, it allows the backup to be usable
Copilot
AI
Nov 25, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The function does not return a non-zero exit code when unmount fails. Since the script uses set -eo pipefail at the top, and this function temporarily disables errors with set +e, a failed unmount will not cause the script to exit with an error status. This means backup jobs will report success even when the unmount fails, which contradicts the PR's goal of fixing "random backup failures." Consider adding return 1 or exit 1 in the else branch (lines 244-248) to ensure proper error propagation.
| log -ne "Warning: failed to unmount $mount_point, error: $umount_output" | |
| log -ne "Warning: failed to unmount $mount_point, error: $umount_output" | |
| return 1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
umount_operation()function lacks documentation explaining its purpose, behavior, and return value. Consider adding a comment block describing: (1) that it waits up to 10 seconds for the mount point to become idle, (2) that it attempts to unmount and remove the directory, and (3) its error handling behavior (currently does not fail the script on unmount failure).