Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save brozkeff/76a154e959a93dfcfb74a368d1206946 to your computer and use it in GitHub Desktop.
Save brozkeff/76a154e959a93dfcfb74a368d1206946 to your computer and use it in GitHub Desktop.
bash script to backup LUKS headers and dumpfiles of selected volumes (cryptsetup luksDump and luksHeaderBackup)
#!/bin/bash
declare -A arrayVolumes
# HOWTO: Enter new row with names of the volumes how you want your files to be named and their uuids
# You can find UUIDs via lsblk -o NAME,UUID. Use UUID of the /dev/sdx1 encrypted volume not the already mounted luks-xxx mapper
arrayVolumes[somevolume]="0e7d8c5e-fe46-4c24-bdfe-041e28e2055b"
arrayVolumes[anothervolume]="5e819f85-f283-41af-a774-6debaa4fa740"
listOfVolumes=$( echo "${!arrayVolumes[@]}" )
if (whiptail --title "Backup of LUKS headers" --yesno "Do you want to backup to the current folder LUKS header backups of these volumes? ${listOfVolumes} ?" 8 70); then
echo "Trying to backup LUKS headers and luksDumps of volumes that are connected"
else
exit 1 || return 1
fi
for volumeName in "${!arrayVolumes[@]}"; do
echo "Looking if volume named ${volumeName} with UUID ${arrayVolumes[$volumeName]} is currently connected"
if [ -b /dev/disk/by-uuid/${arrayVolumes[$volumeName]} ] ; then
echo "[OK] Volume with UUID ${arrayVolumes[$volumeName]} was found, performing LUKS header backup of ${volumeName}"
cryptsetup luksDump /dev/disk/by-uuid/${arrayVolumes[$volumeName]} > ${volumeName}.luksDump
cryptsetup luksHeaderBackup /dev/disk/by-uuid/${arrayVolumes[$volumeName]} --header-backup-file ${volumeName}.luksheader
fi
done
echo "Volumes from the list that were currently connected have their LUKS headers backed up. Done."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment