Skip to content

TimInTech/Scrape-together-old-photos

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 

Repository files navigation

πŸ“Έ Scrape-together-old-photos - Digital Time Capsule

πŸ•°οΈ Welcome to the Time Capsule Community!

We are on a mission to rediscover and preserve old memories by searching forgotten hard drives, USB devices, and folders for lost photos.

This repository provides a Bash script that automatically scans your external storage devices, extracts images, and organizes them by year and month based on metadata.


πŸ› οΈ Features

βœ… Scans external drives & USB devices for old photos βœ… Detects images (.jpg, .png, .gif, .tiff, .bmp) βœ… Sorts images by year & month based on file metadata βœ… Creates a log file for tracking scanned files


πŸš€ Script: scrape_photos.sh

πŸ“‚ How It Works:

  • The script searches all mounted drives for image files.
  • It copies them into a central backup folder sorted by year and month.
  • A log file keeps track of all extracted images.

πŸ“œ Bash Script (scrape_photos.sh)

Save the following script as scrape_photos.sh, make it executable, and run it.

#!/bin/bash

# Scrape-together-old-photos - Find and recover old photos from external storage
# Author: TimInTech | Version: 1.0
# Description: This script scans connected hard drives & USB devices for old photos and copies them to a central "Recovered" folder.

### πŸ” STEP 1: Define Directories ###
BACKUP_DIR="$HOME/Recovered"
LOG_FILE="$BACKUP_DIR/scrape_log.txt"

# Create backup folder if it doesn't exist
mkdir -p "$BACKUP_DIR"

### πŸ“‚ STEP 2: Find All External Drives ###
echo "[INFO] Searching for connected hard drives & USB devices..." | tee -a "$LOG_FILE"
MOUNT_POINTS=$(lsblk -o MOUNTPOINT,TYPE | grep part | awk '{print $1}')

if [ -z "$MOUNT_POINTS" ]; then
    echo "[WARNING] No external drives found!" | tee -a "$LOG_FILE"
    exit 1
fi

### πŸ–ΌοΈ STEP 3: Search for Photos & Copy Them ###
echo "[INFO] Scanning the following drives: $MOUNT_POINTS" | tee -a "$LOG_FILE"

for DRIVE in $MOUNT_POINTS; do
    echo "[INFO] Scanning $DRIVE for image files..." | tee -a "$LOG_FILE"

    find "$DRIVE" -type f \( -iname "*.jpg" -o -iname "*.png" -o -iname "*.gif" -o -iname "*.tiff" -o -iname "*.bmp" \) | while read -r FILE; do
        # Extract metadata (year and month)
        YEAR=$(stat -c %y "$FILE" | cut -d'-' -f1)
        MONTH=$(stat -c %y "$FILE" | cut -d'-' -f2)

        # Create target folder
        TARGET_DIR="$BACKUP_DIR/$YEAR/$MONTH"
        mkdir -p "$TARGET_DIR"

        # Copy file
        cp -n "$FILE" "$TARGET_DIR"
        echo "[OK] Saved: $FILE β†’ $TARGET_DIR" | tee -a "$LOG_FILE"
    done
done

echo "[DONE] All images have been saved to: $BACKUP_DIR" | tee -a "$LOG_FILE"

πŸ“– Installation & Usage

πŸ”Ή 1. Download the Script

git clone https://github.com/TimInTech/Scrape-together-old-photos.git
cd Scrape-together-old-photos
chmod +x scrape_photos.sh

πŸ”Ή 2. Run the Script

./scrape_photos.sh

πŸ”Ή 3. View the Results

  • πŸ“‚ Images are stored in: ~/Recovered/Year/Month/
  • πŸ“„ Log file: scrape_log.txt

πŸ”§ Additional Commands

πŸ“Œ View Logs

Check the scan log to see which files were processed:

cat ~/Recovered/scrape_log.txt

πŸ“Œ Delete Duplicate Files

If you want to remove duplicate images, use fdupes:

sudo apt install fdupes
fdupes -rd ~/Recovered

πŸ“Œ Manually List External Drives

lsblk | grep -i usb

πŸ“Œ Delete the Backup Folder (If Needed)

rm -rf ~/Recovered

🀝 Contribute

πŸ”Ή Found an issue? Report it! πŸ”Ή Want to improve the script? Submit a Pull Request!