Created
March 30, 2025 17:47
-
-
Save NoDataFound/66035ed9b215283e482d2586a7cc2d66 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Ensure the script runs as root. | |
if [ "$EUID" -ne 0 ]; then | |
exec sudo "$0" "$@" | |
fi | |
BASE_BACKUP="Flipper/backups" | |
SOURCE_DIR="/Volumes/Flipper" | |
DATE=$(date +%Y-%m-%d) | |
TIME=$(date +%H%M%S) | |
echo "Choose an option:" | |
echo "1) Backup from ${SOURCE_DIR} to ${BASE_BACKUP}/${DATE}/" | |
echo "2) Restore from backup in ${BASE_BACKUP} to ${SOURCE_DIR}" | |
read -p "Enter 1 for backup or 2 for restore: " choice | |
case "$choice" in | |
1) | |
DEST_DIR="${BASE_BACKUP}/${DATE}" | |
mkdir -p "$DEST_DIR" | |
LOG_FILE="${BASE_BACKUP}/backup-${DATE}-${TIME}.log" | |
echo "Starting backup. Logging to ${LOG_FILE}" | |
rsync -avh --progress --log-file="$LOG_FILE" "$SOURCE_DIR/" "$DEST_DIR/" | |
;; | |
2) | |
read -p "Enter backup date to restore (YYYY-MM-DD): " backup_date | |
SRC_DIR="${BASE_BACKUP}/${backup_date}" | |
if [ ! -d "$SRC_DIR" ]; then | |
echo "Backup directory ${SRC_DIR} does not exist. Exiting." | |
exit 1 | |
fi | |
LOG_FILE="${BASE_BACKUP}/restore-${backup_date}-${TIME}.log" | |
echo "Starting restore from ${SRC_DIR} to ${SOURCE_DIR}. Logging to ${LOG_FILE}" | |
rsync -avh --progress --log-file="$LOG_FILE" "$SRC_DIR/" "$SOURCE_DIR/" | |
;; | |
*) | |
echo "Invalid option. Exiting." | |
exit 1 | |
;; | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment