53 lines
1.3 KiB
Bash
53 lines
1.3 KiB
Bash
#!/bin/bash
|
|
|
|
# Source the configuration file
|
|
. config.sh # Adjust the path as necessary
|
|
|
|
# Check if the script is run as root
|
|
if [ "$(whoami)" != 'root' ]; then
|
|
echo "Permission Denied"
|
|
exit
|
|
fi
|
|
|
|
# Prepare the log file and start tailing it
|
|
touch "$dst/next.log"
|
|
tail -n0 --pid="$$" -f "$dst/next.log" &
|
|
|
|
# Loop until rsync is successful or the user decides to abort
|
|
while :; do
|
|
if rsync "${args[@]}" -av --link-dest="$dst/current" "$src/" "$dst/next" 2>&1 >> "$dst/next.log"; then
|
|
echo -e "\033[32mBackup successful.\033[0m" # Green color for success
|
|
break
|
|
else
|
|
echo -e "\033[31mBackup failed.\033[0m" # Red color for error
|
|
# Ask the user for the next step
|
|
echo "Do you want to retry, abort, or continue? [r/a/c]"
|
|
read -r response
|
|
case $response in
|
|
r|R)
|
|
echo "Retrying..."
|
|
;;
|
|
a|A)
|
|
echo "Aborting."
|
|
exit 1
|
|
;;
|
|
c|C)
|
|
echo "Continuing..."
|
|
break
|
|
;;
|
|
*)
|
|
echo "Invalid response. Please answer r, a, or c."
|
|
;;
|
|
esac
|
|
fi
|
|
done
|
|
|
|
# Success, clean up
|
|
date=$(date "+%Y-%m-%dT%H:%M:%S")
|
|
mv "$dst/next" "$dst/$date"
|
|
mv "$dst/next.log" "$dst/$date.log"
|
|
unlink "$dst/current"
|
|
unlink "$dst/current.log"
|
|
ln -s "$dst/$date" "$dst/current"
|
|
ln -s "$dst/$date.log" "$dst/current.log"
|