also lock pacman db in after_backup

This commit is contained in:
AustrianToast 2024-07-13 01:11:15 +02:00
parent c28fbf309e
commit 91eb6be7c6
Signed by: AustrianToast
GPG Key ID: 378A29F999424B1C

14
update
View File

@ -1,6 +1,6 @@
#!/usr/bin/bash #!/usr/bin/bash
VERSION="3.0.0" VERSION="3.1"
IGREEN="\033[0;92m" # Intense Green IGREEN="\033[0;92m" # Intense Green
IYELLOW="\033[0;93m" # Intense Yellow IYELLOW="\033[0;93m" # Intense Yellow
IRED='\033[0;91m' # Red IRED='\033[0;91m' # Red
@ -63,6 +63,11 @@ lock_pacman_db() {
su --command="touch /var/lib/pacman/db.lck" su --command="touch /var/lib/pacman/db.lck"
} }
unlock_pacman_db() {
echo -e "${IYELLOW}Trying to unlock the pacman db. Please enter your password.${NO_COLOR}"
su --command="rm --force /var/lib/pacman/db.lck"
}
delete_oldest_backup() { delete_oldest_backup() {
if [[ $(find $BACKUP_LOCATION -name '*$1*' -exec printf %c {} + | wc -c) -ge $BACKUP_AMOUNT ]]; then if [[ $(find $BACKUP_LOCATION -name '*$1*' -exec printf %c {} + | wc -c) -ge $BACKUP_AMOUNT ]]; then
rm --force $(find "$BACKUP_LOCATION" -name '*$1*' | sort -rn | head -1) rm --force $(find "$BACKUP_LOCATION" -name '*$1*' | sort -rn | head -1)
@ -71,6 +76,7 @@ delete_oldest_backup() {
before_backup() { before_backup() {
lock_pacman_db lock_pacman_db
[[ -d $TMP ]] && rm --recursive --force "$TMP" [[ -d $TMP ]] && rm --recursive --force "$TMP"
mkdir --parents "$TMP"/before-backup_"$DATE" "$TMP"/after-backup_"$DATE" mkdir --parents "$TMP"/before-backup_"$DATE" "$TMP"/after-backup_"$DATE"
@ -81,11 +87,12 @@ before_backup() {
mv "$TMP"/before-backup_"$DATE".tar.zst.new "$BACKUP_LOCATION" mv "$TMP"/before-backup_"$DATE".tar.zst.new "$BACKUP_LOCATION"
[[ $SECONDARY_BACKUP_LOCATION ]] && mv "$TMP"/before-backup_"$DATE".tar.zst.new "$SECONDARY_BACKUP_LOCATION" [[ $SECONDARY_BACKUP_LOCATION ]] && mv "$TMP"/before-backup_"$DATE".tar.zst.new "$SECONDARY_BACKUP_LOCATION"
echo -e "${IYELLOW}Trying to unlock the pacman db. Please enter your password.${NO_COLOR}" unlock_pacman_db
su --command="rm --force /var/lib/pacman/db.lck"
} }
after_backup() { after_backup() {
lock_pacman_db
pacman --verbose --query > "$TMP"/after-backup_"$DATE"/pacman-after.txt pacman --verbose --query > "$TMP"/after-backup_"$DATE"/pacman-after.txt
[[ -x /usr/bin/flatpak ]] && flatpak list --all --show-details > "$TMP"/after-backup_"$DATE"/flatpak-after.txt [[ -x /usr/bin/flatpak ]] && flatpak list --all --show-details > "$TMP"/after-backup_"$DATE"/flatpak-after.txt
tar --create --zstd --file "$TMP"/after-backup_"$DATE".tar.zst.new "$TMP"/after-backup_"$DATE" > /dev/null 2>&1 tar --create --zstd --file "$TMP"/after-backup_"$DATE".tar.zst.new "$TMP"/after-backup_"$DATE" > /dev/null 2>&1
@ -100,6 +107,7 @@ after_backup() {
mv "$BACKUP_LOCATION"/before-backup_"$DATE".tar.zst.new "$BACKUP_LOCATION"/before-backup_"$DATE".tar.zst 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 [[ $SECONDARY_BACKUP_LOCATION ]] && mv "$SECONDARY_BACKUP_LOCATION"/before-backup_"$DATE".tar.zst.new "$SECONDARY_BACKUP_LOCATION"/before-backup_"$DATE".tar.zst
unlock_pacman_db
rm --recursive --force "$TMP" rm --recursive --force "$TMP"
} }