Initial commit: combine nas_tool, nas_webdav, sync-utils
This commit is contained in:
Executable
+125
@@ -0,0 +1,125 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Move Small Files Test - Start with smallest files first
|
||||
|
||||
set -e
|
||||
|
||||
echo "=== Move Small Files Test ==="
|
||||
echo ""
|
||||
|
||||
NAS_PATH="/Volumes/Download/temp documents from MAc"
|
||||
DOCS_PATH="$HOME/Documents"
|
||||
|
||||
# Check NAS is mounted
|
||||
if [ ! -d "$NAS_PATH" ]; then
|
||||
echo "⚠️ NAS not mounted at: $NAS_PATH"
|
||||
echo " Please check your mount point"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Check current space
|
||||
FREE_SPACE=$(df / | tail -1 | awk '{print $4}')
|
||||
FREE_SPACE_GB=$(echo "scale=2; $FREE_SPACE / 1024 / 1024" | bc)
|
||||
echo "Current free space: ${FREE_SPACE_GB}GB"
|
||||
echo ""
|
||||
|
||||
# Create destination
|
||||
mkdir -p "$NAS_PATH/Documents"
|
||||
|
||||
echo "🔍 Finding smallest folders/files to move first..."
|
||||
echo ""
|
||||
|
||||
# Get list sorted by size (smallest first)
|
||||
du -h -d 1 "$DOCS_PATH" 2>/dev/null | sort -h | while read size item; do
|
||||
# Skip the total line
|
||||
if [ "$item" = "$DOCS_PATH" ]; then
|
||||
continue
|
||||
fi
|
||||
|
||||
FOLDER_NAME=$(basename "$item")
|
||||
|
||||
# Skip if it's not a directory
|
||||
if [ ! -d "$item" ]; then
|
||||
continue
|
||||
fi
|
||||
|
||||
# Show what we found
|
||||
echo "Found: $FOLDER_NAME ($size)"
|
||||
done
|
||||
|
||||
echo ""
|
||||
echo "📦 Moving smallest items first (under 1GB)..."
|
||||
echo ""
|
||||
|
||||
MOVED_COUNT=0
|
||||
|
||||
# Move items under 1GB first
|
||||
du -h -d 1 "$DOCS_PATH" 2>/dev/null | sort -h | while read size item; do
|
||||
# Skip the total line
|
||||
if [ "$item" = "$DOCS_PATH" ]; then
|
||||
continue
|
||||
fi
|
||||
|
||||
# Skip if not a directory
|
||||
if [ ! -d "$item" ]; then
|
||||
continue
|
||||
fi
|
||||
|
||||
FOLDER_NAME=$(basename "$item")
|
||||
|
||||
# Check if size is under 1GB (look for M or K, not G)
|
||||
if echo "$size" | grep -qE "[0-9]+[MK]"; then
|
||||
echo "Moving: $FOLDER_NAME ($size)..."
|
||||
|
||||
if mv -v "$item" "$NAS_PATH/Documents/" 2>&1 | tail -3; then
|
||||
echo " ✅ Successfully moved"
|
||||
MOVED_COUNT=$((MOVED_COUNT + 1))
|
||||
|
||||
# Show progress
|
||||
REMAINING=$(du -sh "$DOCS_PATH" 2>/dev/null | awk '{print $1}')
|
||||
MOVED=$(du -sh "$NAS_PATH/Documents" 2>/dev/null | awk '{print $1}')
|
||||
FREE_NOW=$(df / | tail -1 | awk '{print $4}')
|
||||
FREE_NOW_GB=$(echo "scale=2; $FREE_NOW / 1024 / 1024" | bc)
|
||||
|
||||
echo " Progress: $MOVED on NAS, $REMAINING remaining"
|
||||
echo " Free space: ${FREE_NOW_GB}GB"
|
||||
echo ""
|
||||
|
||||
# Ask to continue after a few moves
|
||||
if [ $MOVED_COUNT -ge 3 ]; then
|
||||
read -p " Continue with more small files? (y/n) " -n 1 -r
|
||||
echo ""
|
||||
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
|
||||
echo " Stopped. Run again to continue."
|
||||
break
|
||||
fi
|
||||
MOVED_COUNT=0
|
||||
fi
|
||||
else
|
||||
echo " ⚠️ Error moving $FOLDER_NAME"
|
||||
echo " Continuing with next..."
|
||||
fi
|
||||
echo ""
|
||||
fi
|
||||
done
|
||||
|
||||
echo ""
|
||||
echo "📊 Summary:"
|
||||
REMAINING=$(du -sh "$DOCS_PATH" 2>/dev/null | awk '{print $1}')
|
||||
MOVED=$(du -sh "$NAS_PATH/Documents" 2>/dev/null | awk '{print $1}')
|
||||
FREE_NOW=$(df / | tail -1 | awk '{print $4}')
|
||||
FREE_NOW_GB=$(echo "scale=2; $FREE_NOW / 1024 / 1024" | bc)
|
||||
|
||||
echo " Moved to NAS: $MOVED"
|
||||
echo " Remaining: $REMAINING"
|
||||
echo " Free space now: ${FREE_NOW_GB}GB"
|
||||
echo ""
|
||||
|
||||
if [ "$REMAINING" != "0B" ] && [ -n "$REMAINING" ]; then
|
||||
echo "✅ Test successful! You can now:"
|
||||
echo " 1. Run this script again to move more small files"
|
||||
echo " 2. Or move larger files manually"
|
||||
echo " 3. Or use: ./safe_move_documents.sh for automated chunked moves"
|
||||
fi
|
||||
|
||||
echo ""
|
||||
Reference in New Issue
Block a user