2021-04-15 10:27:27 +02:00
|
|
|
#!/bin/bash
|
|
|
|
export LANG="en_US.UTF-8"
|
|
|
|
backupcfg="/etc/backup.cfg"
|
|
|
|
ziel="/var/lib/backup/ziel"
|
2021-04-18 11:38:18 +02:00
|
|
|
cfg="/etc/btrbk/btrbk.conf.void"
|
|
|
|
|
|
|
|
fhelp() {
|
|
|
|
echo "Nutze es so:"
|
|
|
|
echo "sudo backup"
|
|
|
|
echo "sudo backup poweroff (um den Rechner nach dem Backup herunterzufahren.)"
|
|
|
|
#echo "sudo backup update (um den Rechner nach dem Backup up zu daten.)"
|
|
|
|
#echo "update und poweroff sind mixbar"
|
|
|
|
echo "sudo backup passwd (um das Passwort für die Backupfestplatte zu ändern.)"
|
|
|
|
}
|
2021-04-15 10:27:27 +02:00
|
|
|
|
|
|
|
if [ "${UID}" -ne "0" ]; then
|
|
|
|
echo "Keine Rootrechte."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2021-04-18 15:52:09 +02:00
|
|
|
for argval in "$@"
|
|
|
|
do
|
|
|
|
case "${argval}" in
|
|
|
|
power|poweroff|p)
|
|
|
|
poweroff=y
|
|
|
|
;;
|
|
|
|
help|-h|--help|h)
|
|
|
|
fhelp
|
|
|
|
exit
|
|
|
|
;;
|
2021-05-10 09:24:40 +02:00
|
|
|
update) update=y ;;
|
|
|
|
passwd) passwd=y ;;
|
|
|
|
clean) do=clean ;;
|
|
|
|
run) do=run ;;
|
2021-04-18 15:52:09 +02:00
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
2021-05-10 09:24:40 +02:00
|
|
|
test -z "${do}" && do=run
|
2021-04-15 10:27:27 +02:00
|
|
|
|
2021-05-10 09:24:40 +02:00
|
|
|
if [[ ! -f /etc/btrbk/btrbk.conf ]]; then
|
|
|
|
if [[ -f "${backupcfg}" ]]; then
|
|
|
|
source "${backupcfg}"
|
|
|
|
else
|
|
|
|
echo "${backupcfg} fehlt."
|
|
|
|
echo "Diese Datei wird normalerweise durch \`void-createbackupcontainer\`"
|
|
|
|
echo "angelegt. Bitte Sprich mit deinem Systemadministrator."
|
|
|
|
fi
|
2021-04-15 10:27:27 +02:00
|
|
|
|
2021-05-10 09:24:40 +02:00
|
|
|
if [ -z "${UUID}" ]; then
|
|
|
|
echo "Keine Backupplatte angegeben."
|
|
|
|
exit 1
|
|
|
|
fi
|
2021-04-15 10:27:27 +02:00
|
|
|
|
2021-05-10 09:24:40 +02:00
|
|
|
if [ ! -e "/dev/disk/by-uuid/${UUID}" ]; then
|
|
|
|
echo "Bitte Backupfestplatte anschliessen."
|
|
|
|
exit 1
|
|
|
|
fi
|
2021-04-15 10:27:27 +02:00
|
|
|
|
2021-05-10 09:24:40 +02:00
|
|
|
if [ -e /tmp/backup ]; then
|
|
|
|
echo "Es läuft schon ein Backupvorgang oder wurde nicht richtig beendet."
|
|
|
|
echo "Bei letzterem: 'sudo rm -rf /tmp/backup'"
|
|
|
|
exit 1
|
2021-04-15 10:27:27 +02:00
|
|
|
fi
|
2021-05-10 09:24:40 +02:00
|
|
|
touch /tmp/backup
|
|
|
|
|
|
|
|
if [[ "${passwd}" == "y" ]]; then
|
|
|
|
cryptsetup luksChangeKey "/dev/disk/by-uuid/${UUID}"
|
|
|
|
rm -rf /tmp/backup
|
|
|
|
exit 0
|
2021-04-15 10:27:27 +02:00
|
|
|
fi
|
|
|
|
|
2021-05-10 09:24:40 +02:00
|
|
|
function finish {
|
|
|
|
sync
|
|
|
|
if [ "${poweroff}" = "y" ]; then
|
|
|
|
shutdown -h now
|
|
|
|
fi
|
|
|
|
sleep 4
|
|
|
|
umount "${ziel}"
|
|
|
|
echo " "
|
|
|
|
echo " "
|
|
|
|
if [[ "${MOUNTEDBY}" == "script" ]]; then
|
|
|
|
cryptsetup close "luks-${UUID}"
|
|
|
|
echo "Festplatte kann nun sicher entfernt werden."
|
2021-05-11 09:21:21 +02:00
|
|
|
elif [[ "${MOUNTEDBY}" == "de" ]]; then
|
2021-05-10 09:24:40 +02:00
|
|
|
echo "Festplatte bitte mit der grafischen Oberflaeche auswerfen (wie ein USB-Stick)"
|
|
|
|
echo ""
|
|
|
|
echo "oder:"
|
|
|
|
echo "sudo umount /dev/mapper/luks-${UUID}"
|
|
|
|
echo "sudo cryptsetup close luks-${UUID}"
|
|
|
|
echo ""
|
|
|
|
fi
|
|
|
|
rm -rf /tmp/backup
|
|
|
|
echo "FERTIG"
|
|
|
|
|
|
|
|
}
|
|
|
|
trap finish EXIT
|
2021-04-15 10:27:27 +02:00
|
|
|
|
2021-05-11 09:21:21 +02:00
|
|
|
if mountpoint -q -x "/dev/mapper/luks-${UUID}" > /dev/null; then
|
|
|
|
MOUNTEDBY="de"
|
|
|
|
else
|
2021-05-10 09:24:40 +02:00
|
|
|
if ! cryptsetup open UUID="${UUID}" "luks-${UUID}"; then
|
|
|
|
echo "Konnte /dev/disk/by-uuid/${UUID} nicht öffnen."
|
|
|
|
exit
|
|
|
|
fi
|
|
|
|
MOUNTEDBY="script"
|
|
|
|
fi
|
|
|
|
|
|
|
|
if ! mount "/dev/mapper/luks-${UUID}" "${ziel}"; then
|
|
|
|
echo "Konnte /dev/mapper/luks-${UUID} in ${ziel} nicht mounten."
|
2021-04-15 10:27:27 +02:00
|
|
|
exit
|
|
|
|
fi
|
|
|
|
else
|
2021-05-10 09:24:40 +02:00
|
|
|
cfg="/etc/btrbk/btrbk.conf"
|
2021-04-15 10:27:27 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
if mountpoint -q /var/lib/backup/quelle/bootfs; then
|
2021-05-07 18:52:50 +02:00
|
|
|
mkdir -p /var/lib/backup/quelle/bootfs/system/backup "/var/lib/backup/ziel/void/bootfs"
|
|
|
|
boot="backupboot"
|
2021-04-15 10:27:27 +02:00
|
|
|
fi
|
|
|
|
|
2021-05-09 18:03:52 +02:00
|
|
|
mkdir -p /var/lib/backup/quelle/rootfs/system/backup "/var/lib/backup/ziel/void/rootfs" "/var/lib/backup/ziel/void/homefs"
|
2021-05-07 18:52:50 +02:00
|
|
|
for t in backup "${boot}"; do
|
2021-04-15 10:27:27 +02:00
|
|
|
if [[ "${t}" ]]; then
|
2021-05-11 09:21:21 +02:00
|
|
|
btrbk --config="${cfg}" --progress --quiet clean "${t}"
|
2021-05-10 09:24:40 +02:00
|
|
|
if ! btrbk --config="${cfg}" --progress --quiet "${do}" "${t}"; then
|
2021-04-15 10:27:27 +02:00
|
|
|
btrbk --config="${cfg}" --progress --quiet clean
|
|
|
|
echo "Wegen Fehler nicht herunterfahren."
|
|
|
|
poweroff=n
|
2021-04-18 15:52:09 +02:00
|
|
|
exit
|
2021-04-15 10:27:27 +02:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
done
|