March 17, 20251 yr Hello im using one of the shell scripts to backup data from my unraid server. Instead of naming each directory to backup within the script i’d rather like to use one directory which contains softlinks to the directories to backup. Where is the best place to put that? I placed them in /mnt/backup-links which seemed to be not the best idea. Thank you for help!
March 17, 20251 yr Community Expert Solution make a share and place them in a directory or use linux temp location... /tmp this will write the backup files into ram though... here is a script example: 1 Create a share (if not already created). 2 Create a directory (/mnt/user/backup-links/) to store soft links. 3 Iterate through the soft links and back up the linked directories. 4 Store the backup in a specified location. #!/bin/bash # Define variables LINKS_DIR="/mnt/user/backup-links" # Directory to store soft links BACKUP_DEST="/mnt/user/backups" # Destination for backups DATE=$(date +"%Y-%m-%d_%H-%M-%S") # Timestamp for backup BACKUP_NAME="backup_$DATE.tar.gz" # Backup filename # Ensure the backup directory exists mkdir -p "$BACKUP_DEST" # Ensure the links directory exists mkdir -p "$LINKS_DIR" # Create an array to store backup sources declare -a BACKUP_SOURCES=() # Iterate over soft links in LINKS_DIR for link in "$LINKS_DIR"/*; do if [ -L "$link" ]; then TARGET=$(readlink -f "$link") if [ -d "$TARGET" ]; then BACKUP_SOURCES+=("$TARGET") else echo "Skipping $link, target $TARGET is not a directory." fi fi done # Check if there are directories to back up if [ ${#BACKUP_SOURCES[@]} -eq 0 ]; then echo "No valid directories found in $LINKS_DIR." exit 1 fi # Create the backup tar -czf "$BACKUP_DEST/$BACKUP_NAME" "${BACKUP_SOURCES[@]}" echo "Backup completed: $BACKUP_DEST/$BACKUP_NAME" How to Use: 1 Create a Share for Backup Links In the Unraid GUI, go to Shares → Add Share Name it backup-links Set appropriate permissions 2 Create Soft Links in /mnt/user/backup-links/ Use SSH or terminal: Example: ln -s /mnt/user/documents /mnt/user/backup-links/documents ln -s /mnt/user/photos /mnt/user/backup-links/photos 3 Run the Backup Script Save the script as /boot/config/plugins/user.scripts/scripts/backup_script.sh * User Script Plugin... Alternative: Use /tmp/backup-links/ (RAM) If you want temporary soft links stored in RAM, change: LINKS_DIR="/tmp/backup-links" However, this will be lost after a reboot.
March 31, 20251 yr Author @bmartino1 sorry to be so late with my Thank you very much for this fast solutiont
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.