Torrent Mover v8.0
Description
Torrent Mover is a Bash script designed to automate the processing of completed torrents in Transmission. It moves or copies downloaded files from a Transmission‑reported download location to designated destination directories on your system. This enhanced version includes robust locking, advanced error handling, parallel processing, configurable path mapping, improved archive extraction, and optional file integrity verification.
Features
- Automatic Torrent Processing: Monitors Transmission for completed torrents and processes them based on configurable seeding criteria.
- Configurable Path Mapping: Uses Transmission’s reported download path (e.g.
/downloads
) and maps it to your local file system (e.g./mnt/dsnas2
) via configurable settings. - Robust Locking: Employs
flock
to ensure that only one instance of the script runs at a time. - Advanced Error Handling & Logging: Global error handler and detailed logging (with DEBUG mode support). Optionally, logs to syslog.
- Parallel File Operations: Utilizes GNU Parallel for moving, copying, and generating checksums, enabling efficient multi-threaded processing.
- Archive Extraction: Extracts archives (RAR, ZIP, 7z) into subdirectories at the destination—preserving internal structure—while retaining the archive in the source until seeding criteria are met.
- Directory Deduplication: Prevents re‑processing the same source directory if multiple torrents reference it.
- Optional Integrity Verification: Verifies file integrity by comparing MD5 checksums after transfer.
Requirements
- Bash
- transmission-remote
- GNU Parallel
- unrar, unzip, 7z
- bc
Installation
- Download the Script: Save the script (e.g.,
torrent-mover.sh
) to your desired location (e.g.,/usr/local/bin/
). - Make It Executable:
chmod +x /usr/local/bin/torrent-mover.sh
- Create/Edit the Configuration File: The script expects a configuration file at
/etc/torrent/mover.conf
. See the configuration section below.
Configuration
Edit or create /etc/torrent/mover.conf
with the following content:
# Transmission settings TRANSMISSION_IP="192.168.1.100" # Replace with your Transmission server's IP TRANSMISSION_PORT="9091" # Replace with your Transmission server's port TRANSMISSION_USER="your_username" # Transmission username (if set) TRANSMISSION_PASSWORD="your_password" # Transmission password (if set)Path mapping settings
TRANSMISSION_PATH_PREFIX="/downloads" LOCAL_PATH_PREFIX="/mnt/dsnas2"
Destination directories
DIR_GAMES_DST="/mnt/dsnas1/Games" DIR_APPS_DST="/mnt/dsnas1/Apps" DIR_MOVIES_DST="/mnt/dsnas1/Movies" DIR_BOOKS_DST="/mnt/dsnas1/Books" DEFAULT_DST="/mnt/dsnas1/Other"
Additional storage directories (comma-separated list)
STORAGE_DIRS="/mnt/dsnas/Movies"
Performance settings
PARALLEL_THREADS="32" PARALLEL_PROCESSING=1
Operation mode: "move" or "copy"
COPY_MODE="copy"
File tracking & integrity
PROCESSED_LOG="/var/log/torrent_processed.log" CHECKSUM_DB="/var/lib/torrent/checksums.db"
Logging settings
LOG_FILE="/var/log/torrent_mover.log" LOG_LEVEL="INFO" # Set to "DEBUG" for more verbose logging USE_SYSLOG="false" # Set to "true" to log messages to syslog
Optional integrity verification after transfer ("true" to enable)
CHECK_TRANSFER_INTEGRITY="true"
Usage
Run the script using the following options:
- Dry-run mode (simulate operations):
/usr/local/bin/torrent-mover.sh --dry-run
- Interactive mode (prompt for confirmation):
/usr/local/bin/torrent-mover.sh --interactive
- Cache warmup mode (pre-calculate checksums):
/usr/local/bin/torrent-mover.sh --cache-warmup
- Debug mode (verbose logging):
/usr/local/bin/torrent-mover.sh --debug
You can combine options as needed. For example:
/usr/local/bin/torrent-mover.sh --dry-run --debug
How It Works
- Locking: Uses
flock
to ensure only one instance runs at a time. - Path Translation: The script translates the Transmission-reported path (e.g.,
/downloads
) to the local file system path (e.g.,/mnt/dsnas2
) using the configured mapping. - Torrent Processing: Retrieves torrent info via
transmission-remote
and processes torrents that are 100% complete. It skips torrents already processed or those with duplicate source directories. - File Verification & Deduplication: Compares file checksums between source and destination, and avoids re‑processing if a match is found.
- Archive Extraction: Extracts archives (RAR, ZIP, 7z) into subdirectories within the destination while preserving directory structure. The original archive is retained in the source until seeding criteria are met.
- Seeding Criteria: Checks seeding ratio and time. When thresholds are met, the torrent is removed from Transmission.
- Integrity Check (Optional): Optionally verifies file integrity by comparing MD5 checksums post-transfer.
License
This script is provided as-is without any warranty. Use it at your own risk. Contributions and improvements are welcome.