Add backup.bash

This commit is contained in:
Sofía Aritz 2023-11-01 19:51:57 +00:00
parent c999703c1d
commit daaebe09a9

17
backup.bash Normal file
View file

@ -0,0 +1,17 @@
#!/usr/bin/env bash
ARCHIVE="/var/userbak/$(date -I)-bak.tar.gz"
tar cfz "${ARCHIVE}" /home
echo "Backup stored at ${ARCHIVE}"
read -r -d $'\0' line < <(find /var/userbak/ -maxdepth 1 -type d -printf '%T@ %p\0' 2>/dev/null | sort -z -n)
OLDEST_FILE="${line#* }"
read -p "Do you want to delete ${OLDEST_FILE}? (y/N)" -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]
then
rm "${OLDEST_FILE}"
echo "Done"
fi
# Note: I'm not an expert in Bash, be careful when running this.