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 11:38:18 +02:00
|
|
|
if [[ -f /etc/btrbk/btrbk.conf ]]; then
|
|
|
|
function finish {
|
|
|
|
sync
|
|
|
|
if [ "${poweroff}" = "y" ]; then
|
|
|
|
shutdown -h now
|
|
|
|
fi
|
|
|
|
sleep 4
|
|
|
|
echo "FERTIG"
|
|
|
|
rm -rf /tmp/backup
|
|
|
|
}
|
|
|
|
trap finish EXIT
|
|
|
|
|
|
|
|
if ! btrbk --progress --quiet run backup; then
|
|
|
|
btrbk --progress --quiet clean
|
|
|
|
echo "Wegen Fehler nicht herunterfahren."
|
|
|
|
poweroff=n
|
|
|
|
fi
|
|
|
|
exit
|
|
|
|
fi
|
|
|
|
|
2021-04-15 10:27:27 +02:00
|
|
|
if [[ -f "${backupcfg}" ]]; then
|
|
|
|
source "${backupcfg}"
|
|
|
|
else
|
|
|
|
echo "${backupcfg} fehlt."
|
|
|
|
echo "Entweder:"
|
|
|
|
echo "UUID=\"uuid\" > ${backupcfg}"
|
|
|
|
echo "oder:"
|
|
|
|
echo "\`void-createbackupcontainer\` um eine neue Backupplatte einzurichten."
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -z "${UUID}" ]; then
|
|
|
|
echo "Keine Backupplatte angegeben."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2021-04-18 11:38:18 +02:00
|
|
|
|
2021-04-15 10:27:27 +02:00
|
|
|
|
|
|
|
if [ ! -e "/dev/disk/by-uuid/${UUID}" ]; then
|
|
|
|
echo "Bitte Backupfestplatte anschliessen."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
for argval in "$@"
|
|
|
|
do
|
|
|
|
case "${argval}" in
|
|
|
|
power|poweroff|p)
|
|
|
|
poweroff=y
|
|
|
|
;;
|
|
|
|
help|-h|--help|h)
|
|
|
|
fhelp
|
|
|
|
exit
|
|
|
|
;;
|
|
|
|
update)
|
|
|
|
update=y
|
|
|
|
;;
|
|
|
|
passwd)
|
|
|
|
passwd=y
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
|
|
|
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
|
|
|
|
fi
|
|
|
|
touch /tmp/backup
|
|
|
|
|
|
|
|
if [[ "${passwd}" == "y" ]]; then
|
|
|
|
cryptsetup luksChangeKey "/dev/disk/by-uuid/${UUID}"
|
|
|
|
rm -rf /tmp/backup
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
|
|
|
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."
|
|
|
|
elif [[ "${MOUNTEDBY}" == "gnome" ]]; then
|
|
|
|
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
|
|
|
|
|
|
|
|
if [ ! $(mountpoint -q -x "/dev/mapper/luks-${UUID}") ]; then
|
|
|
|
if ! cryptsetup open UUID="${UUID}" "luks-${UUID}"; then
|
|
|
|
echo "Konnte /dev/disk/by-uuid/${UUID} nicht öffnen."
|
|
|
|
exit
|
|
|
|
fi
|
|
|
|
MOUNTEDBY="script"
|
|
|
|
else
|
|
|
|
MOUNTEDBY="gnome"
|
|
|
|
fi
|
|
|
|
|
|
|
|
if ! mount "/dev/mapper/luks-${UUID}" "${ziel}"; then
|
|
|
|
echo "Konnte /dev/mapper/luks-${UUID} in ${ziel} nicht mounten."
|
|
|
|
exit
|
|
|
|
fi
|
|
|
|
|
|
|
|
if mountpoint -q /var/lib/backup/quelle/bootfs; then
|
|
|
|
mkdir -p "/var/lib/backup/ziel/void/bootfs"
|
|
|
|
backupbootfs="backupbootfs"
|
|
|
|
fi
|
|
|
|
|
|
|
|
mkdir -p "/var/lib/backup/ziel/void/{rootfs,homefs}"
|
|
|
|
for t in backuprootfs "${backupbootfs}"; do
|
|
|
|
if [[ "${t}" ]]; then
|
|
|
|
if ! btrbk --config="${cfg}" --progress --quiet run "${t}"; then
|
|
|
|
btrbk --config="${cfg}" --progress --quiet clean
|
|
|
|
echo "Wegen Fehler nicht herunterfahren."
|
|
|
|
poweroff=n
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
|
|
|
|
|
|
|
#if [[ "${update}" = "y" ]]; then
|
|
|
|
# if command -v voidupdate >/dev/null; then
|
|
|
|
# if ! voidupdate; then
|
|
|
|
# echo "UPDATE FAILED, nicht runterfahren"
|
|
|
|
# poweroff=n
|
|
|
|
# fi
|
|
|
|
# else
|
|
|
|
# if ! apt-get -y -q upgrade; then
|
|
|
|
# echo "UPDATE FAILED, nicht runterfahren"
|
|
|
|
# poweroff=n
|
|
|
|
# fi
|
|
|
|
# fi
|
|
|
|
#fi
|