2018-02-26 02:41:29 +01:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
set -ex
|
|
|
|
|
|
|
|
if [[ $EUID -ne 0 ]]; then
|
|
|
|
echo "This script must be run as root" 1>&2
|
2018-04-02 03:20:05 +02:00
|
|
|
sudo $0 $1 $2 $3 $4 $5 $6 $7 $8 $9
|
2018-02-26 02:41:29 +01:00
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
echo "Als root Angemeldet"
|
|
|
|
|
2018-08-22 01:51:29 +02:00
|
|
|
if [ "make" == "$1" ]; then
|
2018-02-26 02:41:29 +01:00
|
|
|
|
|
|
|
while (( "$(expr $# - 1)" ))
|
|
|
|
do
|
|
|
|
|
|
|
|
pfad="${2}"
|
|
|
|
|
|
|
|
echo `date "+%Y%m%d-%H%M%S"` > /run/btrfs-root/__current/${pfad}/SNAPSHOT
|
|
|
|
echo "BACKUP" >> /run/btrfs-root/__current/${pfad}/SNAPSHOT
|
|
|
|
|
2018-06-21 06:56:45 +02:00
|
|
|
|
|
|
|
#only root for the fstab
|
|
|
|
if [ "${pfad}" == "ROOT" ]; then
|
2018-07-17 18:26:10 +02:00
|
|
|
sed "s|__current/${pfad}|__snapshot/${pfad}@`head -n 1 /run/btrfs-root/__current/${pfad}/SNAPSHOT`|g;" /etc/fstab.example > /etc/fstab
|
|
|
|
rootsnapshot="y"
|
2018-06-21 06:56:45 +02:00
|
|
|
fi
|
|
|
|
|
2018-02-26 02:41:29 +01:00
|
|
|
mkdir -p /run/btrfs-root/__snapshot/${pfad%/*}
|
2018-06-21 06:56:45 +02:00
|
|
|
btrfs subvolume snapshot /run/btrfs-root/__current/${pfad} /run/btrfs-root/__snapshot/${pfad}@`head -n 1 /run/btrfs-root/__current/${pfad}/SNAPSHOT`
|
|
|
|
#btrfs subvolume snapshot -r /run/btrfs-root/__current/${pfad} /run/btrfs-root/__snapshot/${pfad}@`head -n 1 /run/btrfs-root/__current/${pfad}/SNAPSHOT`
|
2018-02-26 02:41:29 +01:00
|
|
|
|
2018-06-21 06:56:45 +02:00
|
|
|
if ! [ "${pfad}" == "ROOT" ]; then
|
2018-07-17 18:26:10 +02:00
|
|
|
rm /run/btrfs-root/__current/${pfad}/SNAPSHOT
|
2018-06-21 06:56:45 +02:00
|
|
|
fi
|
2018-02-26 02:41:29 +01:00
|
|
|
|
|
|
|
shift
|
|
|
|
|
|
|
|
done
|
|
|
|
|
2018-06-21 14:37:45 +02:00
|
|
|
if [ "${rootsnapshot}" == "y" ]; then
|
2018-06-21 08:11:52 +02:00
|
|
|
#reset-fstab
|
|
|
|
cp /etc/fstab.example /etc/fstab
|
2018-07-17 18:26:10 +02:00
|
|
|
#stable-snapshot-boot
|
|
|
|
if [ -f "/boot/arch-uefi.conf.example" ] && [ "${rootsnapshot}" == "y" ]; then
|
2018-06-21 06:56:45 +02:00
|
|
|
|
2018-08-30 00:12:58 +02:00
|
|
|
cp "$(echo $(find /boot/ -name "initramfs*.img") | cut -d" " -f1)" /boot/initramfs-stable.img
|
|
|
|
cp "$(echo $(find /boot/ -name "vmlinuz*") | cut -d" " -f1)" /boot/vmlinuz-stable
|
2018-06-21 06:56:45 +02:00
|
|
|
|
2018-08-30 00:12:58 +02:00
|
|
|
kernel="/initramfs-stable.img"
|
|
|
|
linuz="/vmlinuz-stable"
|
2018-06-21 06:56:45 +02:00
|
|
|
|
2018-08-30 00:01:18 +02:00
|
|
|
sed "s|%LINUZ%|${linuz}|g;s|%KERNEL%|${kernel}|g;s|rootflags=subvol=__current/ROOT|rootflags=subvol=__snapshot/ROOT@`head -n 1 /run/btrfs-root/__current/ROOT/SNAPSHOT`|g" /boot/arch-uefi.conf.example > /boot/loader/entries/arch-uefi-stable.conf
|
2018-06-21 06:56:45 +02:00
|
|
|
|
2018-07-17 18:26:10 +02:00
|
|
|
if [ -f /run/btrfs-root/__current/ROOT/SNAPSHOT ]; then
|
|
|
|
rm /run/btrfs-root/__current/ROOT/SNAPSHOT
|
|
|
|
fi
|
2018-06-21 06:56:45 +02:00
|
|
|
|
|
|
|
|
2018-07-17 18:26:10 +02:00
|
|
|
fi
|
2018-06-21 06:56:45 +02:00
|
|
|
fi
|
|
|
|
|
2018-02-26 02:41:29 +01:00
|
|
|
elif [ "restore" == "$1" ]; then
|
|
|
|
|
|
|
|
while (( "$(expr $# - 1)" ))
|
|
|
|
do
|
|
|
|
|
|
|
|
pfad="${2}"
|
|
|
|
|
|
|
|
if [ -d /run/btrfs-root/__current/${pfad/@*}.old ]; then
|
|
|
|
btrfs subvolume delete /run/btrfs-root/__current/${pfad/@*}.old
|
|
|
|
fi
|
|
|
|
mv /run/btrfs-root/__current/${pfad/@*} /run/btrfs-root/__current/${pfad/@*}.old
|
|
|
|
btrfs subvolume snapshot /run/btrfs-root/__snapshot/${pfad} /run/btrfs-root/__current/${pfad/@*}
|
|
|
|
|
|
|
|
shift
|
|
|
|
|
|
|
|
done
|
|
|
|
|
|
|
|
|
|
|
|
btrfs subvolume list -p /
|
|
|
|
|
|
|
|
#echo "Bitte noch die /etc/fstab editieren und die neuen IDs eintragen!!!"
|
|
|
|
|
|
|
|
echo "Bitte damit die Änderungen wirksam werden das System neustarten!!!"
|
|
|
|
|
|
|
|
#reboot
|
|
|
|
|
2018-08-18 16:30:44 +02:00
|
|
|
elif [ "delete" == "$1" ]; then
|
|
|
|
|
|
|
|
while (( "$(expr $# - 1)" ))
|
|
|
|
do
|
|
|
|
pfad="${2}"
|
|
|
|
|
|
|
|
if btrfs subvolume delete /run/btrfs-root/__snapshot/${pfad}\@* ;then
|
|
|
|
echo "${pfad} erfolgreich gelöscht!!!"
|
|
|
|
else
|
|
|
|
echo "${pfad} konnte nicht gefunden werden!!!"
|
|
|
|
fi
|
|
|
|
|
|
|
|
shift
|
|
|
|
done
|
|
|
|
|
2018-02-26 02:41:29 +01:00
|
|
|
else
|
|
|
|
|
|
|
|
echo "bash ./snapshot.sh PARAMETER PFAD"
|
|
|
|
echo "Parameters: make restore"
|
|
|
|
echo "make ROOT home opt var/cache/pacman/pkg"
|
|
|
|
echo "restore ROOT@20170725-235544 home@20170725-235544 opt@20170725-235544 var/cache/pacman/pkg@20170725-235544"
|
|
|
|
|
|
|
|
btrfs subvolume list -p /
|
|
|
|
|
|
|
|
fi
|
2018-08-18 16:30:44 +02:00
|
|
|
|
|
|
|
echo "Fertig !!!"
|