configs/arch-config/scripts/archive/evolution-backup.sh

58 lines
1.5 KiB
Bash
Raw Normal View History

#!/usr/bin/env bash
set -euo pipefail
# prompt for password
echo -n "Password: "
read -s -r pass
echo
2021-10-28 09:34:00 +02:00
# prompt a second time
echo -n "Repeat Password: "
read -s -r pass2
echo
# check correctness
if [ ! "$pass" = "$pass2" ]; then
echo "Passwords don't match!"
exit
fi
# go to home dir
cd "$HOME"
# get current date
currdate="$(date +%Y-%m-%d)"
2021-05-21 12:58:45 +02:00
# create backup directory
mkdir -p "$HOME/evolution-mail-backup"
mkdir -p "$HOME/evolution-mail-backup/.config"
mkdir -p "$HOME/evolution-mail-backup/.local"
2021-05-21 12:58:45 +02:00
# copy stuff to backup directory
cp -r "$HOME/.config/evolution/" "$HOME/evolution-mail-backup/.config/"
cp -r "$HOME/.local/share/evolution/" "$HOME/evolution-mail-backup/.local/"
2021-05-21 12:58:45 +02:00
# create archive from backup
2021-10-28 10:25:09 +02:00
tar -c -I"zstd -19 -T0" -f evolution-mail-backup-${currdate}.tar.zst evolution-mail-backup/
2021-05-21 12:58:45 +02:00
# remove backup dir
rm -rf "$HOME/evolution-mail-backup"
2021-05-21 12:58:45 +02:00
# encrypt backup archive
echo '$pass' | gpg -c --batch --yes --passphrase-fd 0 evolution-mail-backup-${currdate}.tar.zst
2021-05-21 12:58:45 +02:00
# remove unencrypted archive
rm evolution-mail-backup-${currdate}.tar.zst
2021-05-21 12:58:45 +02:00
# put encrypted archive into backups folder
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