now supports secondary backup

This commit is contained in:
AustrianToast 2024-07-07 01:30:36 +02:00
parent 2fff3ce2a2
commit 0db312e8a0
Signed by: AustrianToast
GPG Key ID: 378A29F999424B1C
2 changed files with 15 additions and 9 deletions

8
update
View File

@ -20,7 +20,8 @@ if [ ! -d $BACKUP_LOCATION ]; then
esac
fi
if [ ! -d $SECONDARY_BACKUP_LOCATION ]; then
if [ $SECONDARY_BACKUP_LOCATION ]; then
if [ ! -d $SECONDARY_BACKUP_LOCATION ]; then
echo -e "${IYELLOW}Secondary Backup location doesn't exist${NO_COLOR}"
read -p "Do you want to create the path and continue? [y/N]" input
case $input in
@ -28,6 +29,7 @@ if [ ! -d $SECONDARY_BACKUP_LOCATION ]; then
[Nn]) exit 0;;
* ) exit 0 ;;
esac
fi
fi
trap interrupt_function INT
@ -81,6 +83,7 @@ before_backup() {
tar --create --zstd --file "$TMP"/before-backup_"$DATE".tar.zst.new "$TMP"/before-backup_"$DATE" /var/lib/pacman/local > /dev/null 2>&1 # for some reason it needs the output suppresion
mv "$TMP"/before-backup_"$DATE".tar.zst.new "$BACKUP_LOCATION"
[[ $SECONDARY_BACKUP_LOCATION ]] && mv "$TMP"/before-backup_"$DATE".tar.zst.new "$SECONDARY_BACKUP_LOCATION"
sudo rm --force /var/lib/pacman/db.lck
}
@ -91,11 +94,14 @@ after_backup() {
tar --create --zstd --file "$TMP"/after-backup_"$DATE".tar.zst.new "$TMP"/after-backup_"$DATE" > /dev/null 2>&1
mv "$TMP"/after-backup_"$DATE".tar.zst.new "$BACKUP_LOCATION"
[[ $SECONDARY_BACKUP_LOCATION ]] && mv "$TMP"/before-backup_"$DATE".tar.zst.new "$SECONDARY_BACKUP_LOCATION"
delete_oldest_backup after-backup
mv "$BACKUP_LOCATION"/after-backup_"$DATE".tar.zst.new "$BACKUP_LOCATION"/after-backup_"$DATE".tar.zst
[[ $SECONDARY_BACKUP_LOCATION ]] && mv "$SECONDARY_BACKUP_LOCATION"/after-backup_"$DATE".tar.zst.new "$SECONDARY_BACKUP_LOCATION"/after-backup_"$DATE".tar.zst
delete_oldest_backup before-backup
mv "$BACKUP_LOCATION"/before-backup_"$DATE".tar.zst.new "$BACKUP_LOCATION"/before-backup_"$DATE".tar.zst
[[ $SECONDARY_BACKUP_LOCATION ]] && mv "$SECONDARY_BACKUP_LOCATION"/before-backup_"$DATE".tar.zst.new "$SECONDARY_BACKUP_LOCATION"/before-backup_"$DATE".tar.zst
rm --recursive --force "$TMP"
}

View File

@ -2,7 +2,7 @@
BACKUP_LOCATION=~/
# optional secondary backup loaction
SECONDARY_BACKUP_LOCATION=/dev/null
#SECONDARY_BACKUP_LOCATION=~/
# use this pacman-wrapper
PACMAN_WRAPPER=yay