2021-05-21 11:45:34 +02:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
set -euo pipefail
|
|
|
|
|
2021-07-08 08:31:01 +02:00
|
|
|
# prompt for password
|
2021-07-12 08:25:06 +02:00
|
|
|
echo -n "Password: "
|
2021-07-08 08:31:01 +02:00
|
|
|
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
|
|
|
|
|
2021-05-21 11:45:34 +02:00
|
|
|
# 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
|
2021-05-21 11:45:34 +02:00
|
|
|
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
|
2021-05-21 11:45:34 +02:00
|
|
|
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 11:45:34 +02:00
|
|
|
|
2021-05-21 12:58:45 +02:00
|
|
|
# remove backup dir
|
2021-05-21 11:45:34 +02:00
|
|
|
rm -rf "$HOME/evolution-mail-backup"
|
|
|
|
|
2021-05-21 12:58:45 +02:00
|
|
|
# encrypt backup archive
|
2021-05-21 11:45:34 +02:00
|
|
|
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
|
2021-05-21 11:45:34 +02:00
|
|
|
rm evolution-mail-backup-${currdate}.tar.zst
|
|
|
|
|
2021-05-21 12:58:45 +02:00
|
|
|
# put encrypted archive into backups folder
|
2021-05-21 11:45:34 +02:00
|
|
|
mv evolution-mail-backup-${currdate}.tar.zst.gpg "$HOME/Nextcloud/backups/"
|
2022-04-10 14:56:08 +02:00
|
|
|
|
|
|
|
# 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
|