-
Notifications
You must be signed in to change notification settings - Fork 35
Enhance backup script with pigz support #9
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 | ||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -84,12 +84,24 @@ if [ ! -f "$backupFileName" ]; then | |||||||||||||||||||||||||||||||||||||||||||
| echo "🚸 Docker not stopped, continuing with the backup" | ||||||||||||||||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| # Choose compressor | ||||||||||||||||||||||||||||||||||||||||||||
| if command -v pigz >/dev/null 2>&1; then | ||||||||||||||||||||||||||||||||||||||||||||
| echo "✅ Using pigz for parallel gzip" | ||||||||||||||||||||||||||||||||||||||||||||
| compressor="pigz -p$(nproc)" | ||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||
| compressor="pigz -p$(nproc)" | |
| compressor="pigz -p${NPROC:-$(nproc 2>/dev/null || echo 4)}" |
Copilot
AI
Dec 29, 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 tar exit code handling allows exit code 1 to pass (which indicates files changed during archival). While this is likely intentional given the --warning=no-file-changed flag, the condition should be "if [ $rc -ne 0 ] && [ $rc -ne 1 ]; then" or "if [ $rc -gt 1 ]; then" to be explicit about which codes are acceptable. The current implementation correctly uses -gt 1, but a comment explaining that exit code 1 is acceptable (files changed during read) would improve clarity.
| rc=$? | |
| rc=$? | |
| # tar exit code 0 = success, 1 = files changed during read (acceptable with --warning=no-file-changed) |
Copilot
AI
Nov 8, 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.
Missing semicolon at the end of the statement on line 171. The script's existing style consistently uses semicolons. Add one for consistency:
echo '🚸 Extracting backup file...';| echo '🚸 Extracting backup file...' | |
| echo '🚸 Extracting backup file...'; |
Copilot
AI
Nov 8, 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.
Missing semicolon at the end of the statement on line 173. The script's existing style consistently uses semicolons. Add one for consistency:
echo '✅ Using pigz for parallel decompression';| echo '✅ Using pigz for parallel decompression' | |
| echo '✅ Using pigz for parallel decompression'; |
Copilot
AI
Dec 29, 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 pigz compression command includes the number of processors with -p$(nproc), but during decompression, pigz is used without the -p flag. While pigz will auto-detect the number of cores by default, it would be more consistent and explicit to also specify the thread count during decompression, especially since it was explicitly set during compression.
| if ! tar -I pigz -Pxf - -C /; then | |
| if ! tar -I "pigz -p\$(nproc)" -Pxf - -C /; then |
Copilot
AI
Nov 8, 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.
Missing semicolons at the end of statements. The script's existing style (visible in the surrounding remote commands) consistently uses semicolons. Add them for consistency:
else
if ! tar -Pzxf - -C /; then
echo '❌ Backup file extraction failed';
exit 1;
fi
fi| echo '❌ Backup file extraction failed' | |
| exit 1 | |
| echo '❌ Backup file extraction failed'; | |
| exit 1; |
Copilot
AI
Nov 8, 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.
Missing semicolons at the end of statements on lines 175, 176, and 181. While bash doesn't strictly require semicolons before fi, the script's existing style (visible in the surrounding remote commands) consistently uses semicolons. This inconsistency could lead to maintainability issues.
Add semicolons for consistency:
if ! tar -I pigz -Pxf - -C /; then
echo '❌ Backup file extraction failed';
exit 1;
fi| echo '❌ Backup file extraction failed' | |
| exit 1 | |
| fi | |
| else | |
| if ! tar -Pzxf - -C /; then | |
| echo '❌ Backup file extraction failed' | |
| exit 1 | |
| echo '❌ Backup file extraction failed'; | |
| exit 1; | |
| fi | |
| else | |
| if ! tar -Pzxf - -C /; then | |
| echo '❌ Backup file extraction failed'; | |
| exit 1; |
Copilot
AI
Dec 29, 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 extraction logic duplicates error handling code across both branches (pigz and gzip). The conditional could be simplified by determining the decompressor flags first, then calling tar once. This would reduce code duplication and make the logic easier to maintain.
| if command -v pigz >/dev/null 2>&1; then | |
| echo '✅ Using pigz for parallel decompression' | |
| if ! tar -I pigz -Pxf - -C /; then | |
| echo '❌ Backup file extraction failed' | |
| exit 1 | |
| fi | |
| else | |
| if ! tar -Pzxf - -C /; then | |
| echo '❌ Backup file extraction failed' | |
| exit 1 | |
| fi | |
| fi | |
| tar_opts="-Pzxf" | |
| if command -v pigz >/dev/null 2>&1; then | |
| echo '✅ Using pigz for parallel decompression' | |
| tar_opts="-I pigz -Pxf" | |
| fi | |
| if ! tar \$tar_opts - -C /; then | |
| echo '❌ Backup file extraction failed' | |
| exit 1 | |
| fi |
Copilot
AI
Nov 8, 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.
Missing semicolon at the end of the statement. The script's existing style consistently uses semicolons. Add one for consistency:
echo '✅ Backup file extracted';| echo '✅ Backup file extracted' | |
| echo '✅ Backup file extracted'; |
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.
[nitpick] The
-p$(nproc)flag uses all available CPU cores, which could overwhelm the system during migration. Consider limiting the number of threads (e.g.,pigz -p$(($(nproc) - 1))) to leave at least one core available for other processes, or make it configurable.