mirror of
https://github.com/buildplan/du_setup.git
synced 2025-12-29 16:14:59 +00:00
option to choose which directories to back up
This commit is contained in:
41
du_setup.sh
41
du_setup.sh
@@ -3,7 +3,8 @@
|
|||||||
# Debian 12 and Ubuntu Server Hardening Interactive Script
|
# Debian 12 and Ubuntu Server Hardening Interactive Script
|
||||||
# Version: 0.57 | 2025-07-07
|
# Version: 0.57 | 2025-07-07
|
||||||
# Changelog:
|
# Changelog:
|
||||||
# - v0.57: Fix for silent failure at test_backup()
|
# - v0.57: Fix for silent failure at test_backup()2
|
||||||
|
# Option to choose which directories to back up.
|
||||||
# - v0.56: Make tailscale config optional
|
# - v0.56: Make tailscale config optional
|
||||||
# - v0.55: Improving setup_user() - ssh-keygen replaced the option to skip ssh key
|
# - v0.55: Improving setup_user() - ssh-keygen replaced the option to skip ssh key
|
||||||
# - v0.54: Fix for rollback_ssh_changes() - more reliable on newer Ubuntu
|
# - v0.54: Fix for rollback_ssh_changes() - more reliable on newer Ubuntu
|
||||||
@@ -1487,6 +1488,35 @@ setup_backup() {
|
|||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# --- Collect Backup Source Directories ---
|
||||||
|
local BACKUP_DIRS_ARRAY=()
|
||||||
|
while true; do
|
||||||
|
print_info "Enter the full paths of directories to back up, separated by spaces."
|
||||||
|
read -rp "$(echo -e "${CYAN}Default is '/home/${USERNAME}/'. Press Enter for default or provide your own: ${NC}")" -a user_input_dirs
|
||||||
|
|
||||||
|
if [ ${#user_input_dirs[@]} -eq 0 ]; then
|
||||||
|
BACKUP_DIRS_ARRAY=("/home/${USERNAME}/")
|
||||||
|
break
|
||||||
|
fi
|
||||||
|
|
||||||
|
local all_valid=true
|
||||||
|
for dir in "${user_input_dirs[@]}"; do
|
||||||
|
if [[ ! "$dir" =~ ^/ ]]; then
|
||||||
|
print_error "Invalid path: '$dir'. All paths must be absolute (start with '/'). Please try again."
|
||||||
|
all_valid=false
|
||||||
|
break
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
if [[ "$all_valid" == true ]]; then
|
||||||
|
BACKUP_DIRS_ARRAY=("${user_input_dirs[@]}")
|
||||||
|
break
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
# Convert array to a space-separated string for the backup script
|
||||||
|
local BACKUP_DIRS_STRING="${BACKUP_DIRS_ARRAY[*]}"
|
||||||
|
print_info "Directories to be backed up: $BACKUP_DIRS_STRING"
|
||||||
|
|
||||||
# --- Create Exclude File ---
|
# --- Create Exclude File ---
|
||||||
print_info "Creating rsync exclude file at $EXCLUDE_FILE_PATH..."
|
print_info "Creating rsync exclude file at $EXCLUDE_FILE_PATH..."
|
||||||
tee "$EXCLUDE_FILE_PATH" > /dev/null <<'EOF'
|
tee "$EXCLUDE_FILE_PATH" > /dev/null <<'EOF'
|
||||||
@@ -1495,11 +1525,16 @@ setup_backup() {
|
|||||||
.docker/
|
.docker/
|
||||||
.local/
|
.local/
|
||||||
.npm/
|
.npm/
|
||||||
|
.ssh/
|
||||||
.vscode-server/
|
.vscode-server/
|
||||||
*.log
|
*.log
|
||||||
*.tmp
|
*.tmp
|
||||||
node_modules/
|
node_modules/
|
||||||
|
.bashrc
|
||||||
.bash_history
|
.bash_history
|
||||||
|
.bash_logout
|
||||||
|
.cloud-locale-test.skip
|
||||||
|
.profile
|
||||||
.wget-hsts
|
.wget-hsts
|
||||||
EOF
|
EOF
|
||||||
if confirm "Add more directories/files to the exclude list?"; then
|
if confirm "Add more directories/files to the exclude list?"; then
|
||||||
@@ -1549,7 +1584,7 @@ EOF
|
|||||||
# Generated by server setup script on $(date)
|
# Generated by server setup script on $(date)
|
||||||
set -Euo pipefail; umask 077
|
set -Euo pipefail; umask 077
|
||||||
# --- CONFIGURATION ---
|
# --- CONFIGURATION ---
|
||||||
LOCAL_DIR="/home/${USERNAME}/"
|
BACKUP_DIRS="${BACKUP_DIRS_STRING}"
|
||||||
REMOTE_DEST="${BACKUP_DEST}"
|
REMOTE_DEST="${BACKUP_DEST}"
|
||||||
REMOTE_PATH="${REMOTE_BACKUP_PATH}"
|
REMOTE_PATH="${REMOTE_BACKUP_PATH}"
|
||||||
SSH_PORT="${BACKUP_PORT}"
|
SSH_PORT="${BACKUP_PORT}"
|
||||||
@@ -1587,7 +1622,7 @@ exec 200>"$LOCK_FILE"; flock -n 200 || { echo "Backup already running."; exit 1;
|
|||||||
touch "$LOG_FILE"; chmod 600 "$LOG_FILE"; if [[ -f "$LOG_FILE" && $(stat -c%s "$LOG_FILE") -gt 10485760 ]]; then mv "$LOG_FILE" "${LOG_FILE}.1"; fi
|
touch "$LOG_FILE"; chmod 600 "$LOG_FILE"; if [[ -f "$LOG_FILE" && $(stat -c%s "$LOG_FILE") -gt 10485760 ]]; then mv "$LOG_FILE" "${LOG_FILE}.1"; fi
|
||||||
echo "--- Starting Backup at $(date) ---" >> "$LOG_FILE"
|
echo "--- Starting Backup at $(date) ---" >> "$LOG_FILE"
|
||||||
# --- RSYNC COMMAND ---
|
# --- RSYNC COMMAND ---
|
||||||
rsync_output=$(rsync -avz --delete --stats --exclude-from="$EXCLUDE_FILE" -e "ssh -p $SSH_PORT" "$LOCAL_DIR" "${REMOTE_DEST}:${REMOTE_PATH}" 2>&1)
|
rsync_output=$(rsync -avz --delete --stats --exclude-from="$EXCLUDE_FILE" -e "ssh -p $SSH_PORT" $BACKUP_DIRS "${REMOTE_DEST}:${REMOTE_PATH}" 2>&1)
|
||||||
rsync_exit_code=$?; echo "$rsync_output" >> "$LOG_FILE"
|
rsync_exit_code=$?; echo "$rsync_output" >> "$LOG_FILE"
|
||||||
# --- NOTIFICATION ---
|
# --- NOTIFICATION ---
|
||||||
if [[ $rsync_exit_code -eq 0 ]]; then
|
if [[ $rsync_exit_code -eq 0 ]]; then
|
||||||
|
|||||||
Reference in New Issue
Block a user