Evolution remove backups older than the last 3

This commit is contained in:
RealStickman 2022-04-10 14:56:08 +02:00
parent 01221e1082
commit 7d558f3a3c

View File

@ -1,19 +1,6 @@
#!/usr/bin/env bash #!/usr/bin/env bash
set -euo pipefail set -euo pipefail
: '
# give password as argument
if [ $# -eq 1 ]; then
pass=$1
elif [ $# -eq 0 ]; then
echo "Please provide a passphrase"
$(exit 1); echo "$?"
else
echo "Please only insert one argument"
$(exit 1); echo "$?"
fi
'
# prompt for password # prompt for password
echo -n "Password: " echo -n "Password: "
read -s -r pass read -s -r pass
@ -59,3 +46,12 @@ rm evolution-mail-backup-${currdate}.tar.zst
# put encrypted archive into backups folder # put encrypted archive into backups folder
mv evolution-mail-backup-${currdate}.tar.zst.gpg "$HOME/Nextcloud/backups/" mv evolution-mail-backup-${currdate}.tar.zst.gpg "$HOME/Nextcloud/backups/"
# remove more than the last 3 backups
#find "$HOME/Nextcloud/backups/" -name "evolution-mail-backup-*\.tar.zst.gpg" | sort -r | tail -n +4
mapfile -t old_backups < <( find "$HOME/Nextcloud/backups/" -name "evolution-mail-backup-*\.tar.zst.gpg" | sort -r | tail -n +4 )
for backup in "${old_backups[@]}"; do
echo "Removing old backup. $backup"
rm "$backup"
done