Jump to content

Rsync Script Not Excluding Folders


Recommended Posts

Posted

I have been trying to use ChatGPT to create an unraid user script that backups my files to another unraid server. It won't exclude my folders tho - any idea on how to fix it?

 

#!/bin/bash

# Source and Destination Directories
declare -a SOURCE_DIRS=(
    "/mnt/user/APK"
    "/mnt/user/Computer_Apps"
    "/mnt/user/Documents"
    "/mnt/user/data"
    "/mnt/user/Photos"
    "/mnt/user/ss-recordings"
)
DEST_DIR="/mnt/remotes/192.168.1.12_networkbackup/"

# Folders to Exclude
declare -a EXCLUDE_FOLDERS=(
    "/mnt/user/data/media/movies-4k/"
    "/mnt/user/data/media/tv-4k/"
)

# Rsync Options
RSYNC_OPTIONS="-avz --delete --progress"

# Loop through each source directory
for SOURCE_DIR in "${SOURCE_DIRS[@]}"; do
    # Exclude folders
    EXCLUDE_ARGS=""
    for EXCLUDE_FOLDER in "${EXCLUDE_FOLDERS[@]}"; do
        EXCLUDE_ARGS+=" --exclude=${EXCLUDE_FOLDER}"
    done

    # Run rsync
    rsync ${RSYNC_OPTIONS} ${EXCLUDE_ARGS} "${SOURCE_DIR}" "${DEST_DIR}"
done

 

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...