-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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: main
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 | ||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -154,8 +154,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() { | ||||||||||||||||||||||||||||||||||||
|
|
@@ -184,6 +183,8 @@ backup_stopped_vm() { | |||||||||||||||||||||||||||||||||||
| sync | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| ls -l --numeric-uid-gid $dest | awk '{print $5}' | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| umount_operation | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| delete_backup() { | ||||||||||||||||||||||||||||||||||||
|
|
@@ -219,6 +220,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
+224
to
+231
|
||||||||||||||||||||||||||||||||||||
| 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 |
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).