Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
backupninja
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Petr Klíma
backupninja
Commits
5daea406
Commit
5daea406
authored
4 years ago
by
Jérôme Charaoui
Browse files
Options
Downloads
Patches
Plain Diff
sys: improve device/partition discovery
parent
bb609a43
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
CHANGELOG.md
+1
-0
1 addition, 0 deletions
CHANGELOG.md
handlers/sys.in
+53
-48
53 additions, 48 deletions
handlers/sys.in
with
54 additions
and
48 deletions
CHANGELOG.md
+
1
−
0
View file @
5daea406
...
...
@@ -24,6 +24,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
-
[core] wrap report email body to 1000 characters by default (DEBBUG-871793)
-
[core] improve error handling around
`reporthost`
feature
-
[docs] add missing parameters to
`backupninja.conf`
manpage
-
[sys] improve device selection for MBR backup (#11303)
## [1.2.0] - 2021-01-21
...
...
This diff is collapsed.
Click to expand it.
handlers/sys.in
+
53
−
48
View file @
5daea406
...
...
@@ -554,24 +554,39 @@ fi
## PARTITIONS #############################
# here we use sfdisk to dump a listing of all the partitions.
# these files can be used to directly partition a disk of the same size.
if
[
"
$partitions
"
==
"yes"
]
;
then
if
[
"
$dosfdisk
"
==
"yes"
]
;
then
if
[
"
$partitions
"
==
"yes"
]
||
[
"
$luksheaders
"
==
"yes"
]
||
[
"
$mbr
"
==
"yes"
]
;
then
# get a list of block devices on the system
debug
"LC_ALL=C
$LSBLK
--output NAME,TYPE --list --paths 2>/dev/null | grep
\"
disk
$\
"
|
grep
-v
'^/dev/zram'
| @AWK@
'{print \$1}'
"
devices=
`
LC_ALL
=
C
$LSBLK
--output
NAME,TYPE
--list
--paths
2>/dev/null |
grep
"disk$"
|
grep
-v
'^/dev/zram'
| @AWK@
'{print $1}'
`
partitions
=
`
LC_ALL
=
C
$SFDISK
-l
2>/dev/null |grep
"^/dev"
| @AWK@
'{print $1}'
`
if [ "
$devices
" == "" ]; then
warning
"No harddisks found"
warning "
Unable to find any block devices on this system.
"
else
info "
$(
echo
"Devices found:
$devices
"
|
tr
"
\n
"
" "
)
"
fi
# get a list of block device partitions on the system
debug "
LC_ALL
=
C
$SFDISK
-l
2>/dev/null |
grep
\"
^/dev
\"
| @AWK@
'{print \$1}'
"
devparts=
`
LC_ALL
=
C
$SFDISK
-l
2>/dev/null |
grep
"^/dev"
| @AWK@
'{print $1}'
`
if [ "
$devparts
" == "" ]; then
info "
No partitions found on this system.
"
else
info "
$(
echo
"Partitions found:
$partitions
"
|
tr
"
\n
"
" "
)
"
fi
fi
if [ "
$partitions
" == "
yes
" ]; then
if [ "
$dosfdisk
" == "
yes
" ]; then
for dev in
$devices
; do
debug
"
$SFDISK
will try to backup partition tables for device
$dev
"
[ -b
$dev
] || continue
echo
"
${
partitions
}
"
|
grep
-q
"
${
dev
}
"
if
[
$?
-ne
0
]
;
then
if ! echo "
${
devparts
}
" | grep -q "
${
dev
}
"; then
info "
The device
$dev
does not appear to have any partitions
"
continue
fi
# here we use sfdisk to dump a listing of all the partitions.
# these files can be used to directly partition a disk of the same size.
debug "
$SFDISK
will try to backup partition tables
for
device
$dev
"
label=
${
dev
#/dev/
}
label=
${
label
//\//-
}
outputfile=
${
partitionsfile
//__star__/
$label
}
...
...
@@ -590,24 +605,13 @@ if [ "$partitions" == "yes" ]; then
fi
if [ "
$luksheaders
" == "
yes
" ]; then
devices
=
`
LC_ALL
=
C
$LSBLK
--output
NAME,TYPE
--list
--paths
2>/dev/null |
grep
"disk$"
|
grep
-v
'^/dev/zram'
| @AWK@
'{print $1}'
`
if
[
"
$devices
"
==
""
]
;
then
warning
"No harddisks found"
fi
partitions
=
`
LC_ALL
=
C
$SFDISK
-l
2>/dev/null |grep
"^/dev"
| @AWK@
'{print $1}'
`
[
-n
"
$partitions
"
]
||
warning
"No partitions found"
targetdevices
=
""
for
dev
in
$devices
$partitions
;
do
for dev in
$devices
$devparts
; do
[ -b
$dev
] || continue
debug
"
$CRYPTSETUP
isLuks
$dev
"
$CRYPTSETUP
isLuks
$dev
[
$?
-eq
0
]
&&
targetdevices
=
"
$targetdevices
$dev
"
done
for
dev
in
$targetdevices
;
do
if
$CRYPTSETUP
isLuks
$dev
; then
label=
${
dev
#/dev/
}
label=
${
label
//\//-
}
outputfile=
${
luksheadersfile
//__star__/
$label
}
debug
"
Let us
backup the LUKS header
o
f
$dev
"
debug "
$CRYPTSETUP
will try to
backup the LUKS header
f
or
device
$dev
"
debug "
$CRYPTSETUP
luksHeaderBackup
\"
${
dev
}
\"
--header-backup-file
\"
${
outputfile
}
\"
"
output=
`
$CRYPTSETUP
luksHeaderBackup
"
${
dev
}
"
--header-backup-file
"
${
outputfile
}
"
2>&1
`
exit_code=
$?
...
...
@@ -618,17 +622,15 @@ if [ "$luksheaders" == "yes" ]; then
debug "
$output
"
fatal "
The LUKS header of
$dev
could not be saved.
"
fi
fi
done
fi
if [ "
$mbr
" == "
yes
" ]; then
devices
=
`
LC_ALL
=
C
$SFDISK
-l
2>/dev/null |
grep
"^Disk /dev"
| @AWK@
'{print $2}'
|
cut
-d
:
-f1
`
if
[
"
$devices
"
==
""
]
;
then
warning
"No harddisks found"
fi
for dev in
$devices
; do
debug
"Will try to backup MBR tables for device
$dev
"
[ -b
$dev
] || continue
if
$SFDISK
-d
$dev
2>/dev/null | head -n1 | grep "
label: dos
"; then
debug "
$SFDISK
will try to backup MBR tables
for
device
$dev
"
label=
${
dev
#/dev/
}
label=
${
label
//\//-
}
outputfile=
${
mbrfile
//__star__/
$label
}
...
...
@@ -637,6 +639,9 @@ if [ "$mbr" == "yes" ]; then
if [
$?
-ne 0 ]; then
warning "
The MBR
for
$dev
could not be saved.
"
fi
else
info "
The device
$dev
does not appear to contain an MBR.
"
fi
done
fi
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment