This commit is contained in:
Your Name 2023-02-20 17:54:46 -07:00
parent 92f385ecaa
commit 84bf573026

View File

@ -37,9 +37,7 @@ ROOT_MAPPER_NAME='root'
BACKUP_DISK='/dev/disk/by-uuid/727916c5-a526-47d8-8351-9a0479463738'
BACKUP_DISK_MAPPER='usb'
BACKUP_DISK_ROOT_NAME='usbdebian'
#BACKUP_DISK_IMAGES="/home/verita84/Nextcloud/backups"
#BACKUP_DISK_IMAGES="/var/lib/backups"
BACKUP_DISK_IMAGES="$TARGET/@$BACKUP_DISK_ROOT_NAME/$BACKUP_DISK_IMAGES/var/backups"
BACKUP_DISK_IMAGES="$TARGET/@$BACKUP_DISK_ROOT_NAME/var/backups"
######################################
USER="verita84"
USER_PASSWORD="123456"
@ -73,24 +71,35 @@ auto_login() {
}
create-os-snapshots() {
echo
echo "[Creating new snapshots.....]"
echo
#mkdir -p $TARGET/\@$BACKUP_DISK_MAPPER/var/backups
time tar cvpzf $BACKUP_DISK_IMAGES/$1.tgz --exclude=/var/backups --exclude=/volumes/* --exclude=/mnt/* --exclude=/var/tmp/* --exclude=/tmp/* --exclude=/raid/* --exclude=/root/* --exclude=/var/cache/apt/archives/* --exclude=/proc/* --exclude=/.snapshots/* --exclude=$TARGET/* --exclude=/var/lib/libvirt/* --exclude=/dev/* --exclude=/sys/* --exclude=/home/* --exclude=/var/lib/flatpak --exclude=/var/lib/postgresql --exclude=/var/lib/containers /
if [ -z "${2}" ]; then
echo "[Creating new OS snapshot to $BACKUP_DISK_IMAGES/$1.tgz]"
echo
echo
time tar cpzf $BACKUP_DISK_IMAGES/$1.tgz --exclude=/run --exclude=/var/backups --exclude=/volumes/* --exclude=/mnt/* --exclude=/var/tmp/* --exclude=/tmp/* --exclude=/raid/* --exclude=/root/* --exclude=/var/cache/apt/archives/* --exclude=/proc/* --exclude=/.snapshots/* --exclude=$TARGET/* --exclude=/var/lib/libvirt/* --exclude=/dev/* --exclude=/sys/* --exclude=/home/* --exclude=/var/lib/flatpak --exclude=/var/lib/postgresql --exclude=/var/lib/containers /
else
echo "[Creating new OS snapshot to $2/$1.tgz]"
echo
echo
time tar cpzf $2/$1.tgz --exclude=/run --exclude=/var/backups --exclude=/volumes/* --exclude=/mnt/* --exclude=/var/tmp/* --exclude=/tmp/* --exclude=/raid/* --exclude=/root/* --exclude=/var/cache/apt/archives/* --exclude=/proc/* --exclude=/.snapshots/* --exclude=$TARGET/* --exclude=/var/lib/libvirt/* --exclude=/dev/* --exclude=/sys/* --exclude=/home/* --exclude=/var/lib/flatpak --exclude=/var/lib/postgresql --exclude=/var/lib/containers /
fi
chown $USER:$USER $BACKUP_DISK_IMAGES/$1.tgz
}
homeBackup() {
echo
echo "[Copying USER data....]"
echo "[Copying USER data from /home to $TARGET/@home]"
echo
rsync --progress -avz --delete /home/ --exclude=.cache --exclude=.local/share/flatpak --exclude=.local/share/containers $TARGET/\@home/
rsync -a --delete /home/ --exclude=.cache --exclude=.local/share/flatpak --exclude=.local/share/containers $TARGET/\@home/
}
os-backup() {
umount $TARGET
printf "$DISK_PASSWORD" | cryptsetup open $BACKUP_DISK $BACKUP_DISK_MAPPER
if [[ -e "/dev/mapper/$BACKUP_DISK_MAPPER" ]]; then
echo
echo "[Mounting.....]"
@ -125,12 +134,20 @@ os-backup() {
}
os-restore() {
ROOT_CHECK=$(mount | grep ' / ')
if [[ "$ROOT_CHECK" == *"$BACKUP_DISK_ROOT_NAME"* ]]; then
BACKUP_DISK_IMAGES="/var/lib/backups"
fi
partitions
rm -rf $TARGET/usr $TARGET/sbin $TARGET/lib32 $TARGET/libx32 $TARGET/lib $TARGET/vmlinuz* $TARGET/initrd* $TARGET/bin $TARGET/var $TARGET/root $TARGET/opt $TARGET/etc $TARGET/run
echo "[Restirubg OS tarfile from $BACKUP_DISK_IMAGES/$1.tgz]"
echo
tar xfpv $BACKUP_DISK_IMAGES/$2.tgz -C $TARGET/
if [ "$3" = "home" ]; then
rsync -av --progress --delete /home/ $TARGET/home/
rsync -a --delete /home/ $TARGET/home/
fi
fstab
@ -507,7 +524,7 @@ show-help() {
echo "./debian.sh wifi"
echo "./debian.sh bootloader [disk]"
echo "./debian.sh initialize [disk]"
echo "./debian.sh tar [disk]"
echo "./debian.sh tar [disk] [location]"
echo "./debian.sh snapshot"
echo "./debian.sh reomve-snapshot"
echo "./debian.sh btrfs-tweaks"
@ -519,7 +536,7 @@ if [ "$1" = "install" ]; then
elif [ "$1" = "desktop" ]; then
desktop
elif [ "$1" = "tar" ]; then
create-os-snapshots "$2"
create-os-snapshots "$2" "$3"
elif [ "$1" = "kernel-packages" ]; then
kernel-packages
elif [ "$1" = "upgrade-system" ]; then