Skip to content
View in the app

A better way to browse. Learn more.

Unraid

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Script to check rclone dry-run results prior to running (grep problems)

Featured Replies

I'm in the process of building a script to confirm that I am Transferring more files than Deleting prior to executing an rclone sync. It all works very nicely but I cannot seem to grep the deleted and transferred values from the logs.

 

Simple test script below, and full script with system alerts, etc below that. Can anyone tell me what I'm doing wrong with the grep? It always returns null but it works when testing in regex validators.

 

#!/bin/bash

# Example rclone output
rclone_output="Deleted: 24603 (files), 3457 (dirs), 5.602 TiB (freed)
Transferred: 22682 / 22682, 100%"

# Function to extract the first group of numbers
extract_first_number() {
  echo "$1" | grep -Eo '[0-9]+' | head 
}

# Parse Transferred and Deleted counts, extracting only the first group of numbers
transferred_count=$(echo "$rclone_output" | grep 'Transferred: [0-9]+' | tail -1 | extract_first_number)
deleted_count=$(echo "$rclone_output" | grep 'Deleted: [0-9]+' | tail -1 | extract_first_number)

# Output the extracted values
echo "Expected Deleted: 24603, Extracted Deleted: $deleted_count"
echo "Expected Transferred: 22682, Extracted Transferred: $transferred_count"

 

 

Here's the larger script with the logic and the alerts, someone might find it helpful.

 

#!/bin/bash
# Define your rclone remote and paths
LOCAL="unraid:/array/"
REMOTE="Synology:/backup/"
BACKUPNAME="Backup Array"

# Perform a dry run
rclone_output=$(docker exec Nacho-Rclone-Native-GUI rclone sync --dry-run "$LOCAL" "$REMOTE" -v)

# Wait for 5 seconds
sleep 5

# Function to extract the first group of numbers
extract_first_number() {
  echo "$1" | grep -o '[0-9]\+' | head -1
}

# Parse Transferred and Deleted counts, extracting only the first group of numbers
transferred_count=$(echo "$rclone_output" | grep 'Transferred: [0-9]*' | tail -1 | grep -o '[0-9]\+' )
deleted_count=$(echo "$rclone_output" | grep 'Deleted: [0-9]*' | tail -1 | grep -o '[0-9]\+' )

  echo  "Transferred count ($transferred_count) and Deleted count ($deleted_count)"

# Check if Transferred count is greater than Deleted count
if [ "$transferred_count" -gt "$deleted_count" ]; then
  echo "Syncing as Transferred count ($transferred_count) is greater than Deleted count ($deleted_count)"
 
   # Execute the sync command and capture the output
  sync_output=$(docker exec Nacho-Rclone-Native-GUI rclone sync "$LOCAL" "$REMOTE" -v --transfers=1)
 
  if [ $? -eq 0 ]; then
    # Parse the final Transferred and Deleted counts from the sync output, ensuring they are integers
    final_transferred_count=$(echo "$sync_output" | grep -oP 'Transferred: *\d+ / \d+,' | tail -1 | awk '{print $2}')
    final_deleted_count=$(echo "$sync_output" | grep -oP 'Deleted: *\d+ ' | tail -1 | awk '{print $2}')
    
    final_transferred_count=${final_transferred_count:-0}
    final_deleted_count=${final_deleted_count:-0}
    
    # Trigger Unraid system alert on success
    #logger "rclone sync successful: Transferred $final_transferred_count files, Deleted $final_deleted_count files"
    /usr/local/emhttp/webGui/scripts/notify -i normal -s "$BACKUPNAME" -d "Rclone Backup was successful, $final_transferred_count files transfered, $final_deleted_count deleted."
  else
    #logger "rclone sync failed"
    /usr/local/emhttp/webGui/scripts/notify -i warning -s "$BACKUPNAME" -d "Rclone Backup completed, but more files were deleted than transfered, $final_transferred_count files transfered, $final_deleted_count deleted!"

  fi
else
  echo "Skipping sync as Transferred count ($transferred_count) is not greater than Deleted count ($deleted_count)"
  #logger "rclone sync skipped: Transferred count ($transferred_count) is not greater than Deleted count ($deleted_count)"
  /usr/local/emhttp/webGui/scripts/notify -i normal -s "$BACKUPNAME" -d "Rclone Backup was skipped as Transferred count ($transferred_count) is not greater than Deleted count ($deleted_count)"

fi

 

Edited by Kboogie

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...

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.