Skip to content

Repository files navigation

iPhone Auto Backup

Auto-backup iPhone photos & videos to external drive on USB plug-in.
EXIF date archiving, content-hash dedup, zero cloud dependency.

License Platform Language Dependencies ShellCheck Stars Forks Release

English | 中文文档


Why this exists

Every time you plug in your iPhone, macOS wants to open Photos.app or Image Capture — but neither gives you automatic, deduplicated, date-sorted backups to an external drive. iCloud costs money and locks you in. iMazing is $40+. This tool does it for free, with zero cloud, and runs entirely via launchd + libimobiledevice.

Who is this for?

  • Photographers — auto-archive iPhone shoots by EXIF date, no manual sorting
  • Parents — never lose a baby photo again; plug in and it backs up
  • Data hoarders — content-hash dedup means zero redundant copies
  • Privacy-conscious users — zero cloud, zero tracking, files on your disk
  • Anyone with an iPhone — if you have photos on your phone, you need backup

Features

  • Auto-trigger on USB plug-inlaunchd daemon detects iPhone connection, no manual action needed
  • Content-hash dedup — SHA1 of first/last 512KB + file size, never backup the same file twice
  • EXIF date archiving — reads CreateDate / DateTimeOriginal, sorts into YYYY-MM-DD folders
  • Smart photo classification — auto-separates camera photos / screenshots / saved images into subdirectories
  • Device-side pre-filter — skips download entirely when file path + size unchanged (instant pass for already-backed-up files)
  • Integrity verification — compares local vs device file size after AFC download, auto-retries on truncation
  • Sleep prevention — keeps your Mac awake during backup via caffeinate
  • Desktop notifications — macOS native notifications for start / complete / error
  • No cloud, no vendor lock-in — files live on your disk, plain YYYY-MM-DD/001.mov structure

How it works

iPhone (USB)
    │
    ▼
┌─────────────────────────────┐
│  iphone_backup_monitor.sh   │  ← launchd daemon (KeepAlive)
│  Polls idevice_id every 10s │
└──────────┬──────────────────┘
           │ iPhone detected & trusted
           ▼
    ┌──────┴──────┐
    ▼             ▼
 backup_videos   backup_photos
    │             │
    │  ┌──────────┘
    ▼  ▼
 Scan DCIM via afcclient
    │
    ▼
 Device-side pre-filter ──── skip (path+size unchanged)
    │
    ▼
 Download via AFC
    │
    ▼
 Size verify (retry on truncation)
    │
    ▼
 Content hash dedup ──────── skip (hash already seen)
    │
    ▼
 Read EXIF date ──→ fallback: filename ──→ device mtime ──→ _unknown_date
    │
    ▼
 Classify (photo/screenshot/saved)   ← photos only
    │
    ▼
 Archive → /Volumes/Drive/iPhone_Photos/Photos/2026-04-09/001.heic
    │
    ▼
 Set file mtime = EXIF timestamp
    │
    ▼
 macOS notification ✅

Quick Start

# 1. Clone
git clone https://github.com/andersyin/iphone-auto-backup.git
cd iphone-auto-backup

# 2. Edit config FIRST — install refuses the YourExternalDrive placeholders
nano config.sh
# Set BACKUP_ROOT and PHOTO_BACKUP_ROOT to your disk, e.g.
#   BACKUP_ROOT="/Volumes/MyDrive/iPhone_Videos"
#   PHOTO_BACKUP_ROOT="/Volumes/MyDrive/iPhone_Photos"

# 3. Install (Homebrew deps + launchd). Apple Silicon and Intel brew prefixes are auto-detected.
bash install.sh

First run

  1. Mount the external drive named in config.sh.
  2. Plug in the iPhone, unlock it, and tap Trust This Computer.
  3. Watch progress: cat /tmp/iphone_backup_monitor.status
  4. Optional smoke test without waiting for USB: bash backup_videos_v3.sh / bash backup_photos_v3.sh

Backup scripts will not create a fake folder under /Volumes if the disk is unmounted; they notify and exit instead.

Terminal Demo

$ bash backup_videos_v3.sh

[14:23:01] ==== iPhone 视频备份 v3 ====
[OK] iPhone 已连接
[14:23:01] 已阻止 Mac 睡眠 (PID 48291)
[14:23:01] 正在扫描 iPhone...
[OK] 发现 47 个视频

  45% |████████████░░░░░░░░░░░░| 21/47  IMG_4523.MOV
[OK] IMG_4523.MOV → 2026-04-07/001.mov
[SKIP] 内容重复: IMG_4524.MOV
[OK] IMG_4525.MOV → 2026-04-07/002.mov
  ...
[OK] IMG_4569.MOV → 2026-04-09/003.mov

======================================================================
                    iPhone 视频备份报告
======================================================================
同步文件夹:   /Volumes/MyDrive/iPhone_Videos
  共计:       482 个视频文件
  新增:       12 个视频
  跳过:       35 个(已存在/内容重复,其中 28 个设备侧未变、免下载秒过)
  失败:       0 个
======================================================================

Comparison

Feature iCloud Photos Image Capture iMazing This tool
Free 5GB limit Yes $40+ Yes
Auto on USB plug-in No (Wi-Fi) No (manual) Yes Yes
Content-hash dedup No No No Yes
Sort by EXIF date No No Yes Yes
Photo classification No No No Yes
Incremental (skip seen) N/A No Yes Yes (device-side)
No cloud dependency No Yes Yes Yes
Open source N/A No No Yes
File mtime = shoot date N/A No No Yes

Backup Structure

/Volumes/YourDrive/iPhone_Videos/
└── 2026-04-07/
    ├── 001.mov
    └── 002.mov

/Volumes/YourDrive/iPhone_Photos/
├── Photos/
│   └── 2026-04-09/
│       ├── 001.jpg
│       └── 002.heic
├── Screenshots/
│   └── 2026-04-10/
│       └── 001.png
└── Saved_Images/
    └── 2026-04-10/
        └── 001.gif

Configuration (config.sh)

Parameter Description Default
BACKUP_ROOT Video backup target path /Volumes/YourExternalDrive/iPhone_Videos
PHOTO_BACKUP_ROOT Photo backup target path /Volumes/YourExternalDrive/iPhone_Photos
VIDEO_EXTENSIONS Supported video formats MOV MP4 M4V 3GP AVI MKV
PHOTO_EXTENSIONS Supported photo formats JPG JPEG HEIC PNG GIF
AUTO_REFRESH_INDEX Run optional sibling refresh_index.sh after backup (not shipped here) 0 (off)

Dependencies

Tool Purpose Install
libimobiledevice iPhone communication (afcclient / idevicepair) brew install libimobiledevice
exiftool Read EXIF dates from photos/videos brew install exiftool

No macFUSE / ifuse needed. Only macOS built-in tools + 2 Homebrew packages.

Requirements

  • macOS (Apple Silicon or Intel; Homebrew tools are resolved from /opt/homebrew/bin, /usr/local/bin, or PATH)
  • iPhone with USB connection (must click "Trust This Computer")
  • External drive or designated backup directory (edit config.sh before install.sh)

Manual Run

bash backup_videos_v3.sh    # backup videos
bash backup_photos_v3.sh    # backup photos

Logs

cat /tmp/iphone_backup_monitor.status    # monitor state
cat /tmp/iphone_backup_stdout.log        # video backup log
cat /tmp/iphone_photo_backup_stdout.log  # photo backup log

File Structure

iphone-auto-backup/
├── config.sh                             # Configuration (edit before first use)
├── backup_videos_v3.sh                   # Video backup script
├── backup_photos_v3.sh                   # Photo backup script
├── backup_safe.sh                        # Simple backup (v1, copy-only, no dedup)
├── iphone_backup_monitor.sh              # Device watcher daemon
├── rebuild_hash_index.sh                 # Hash index rebuild tool
├── install.sh                            # One-click install (registers launchd)
├── uninstall.sh                          # Uninstall launchd
├── com.user.iphone-backup-monitor.plist  # launchd config (monitor)
├── com.user.iphone-video-backup.plist    # launchd config (legacy video)
└── com.user.iphone-photo-backup.plist    # launchd config (legacy photo)

FAQ

Q: Backup doesn't auto-trigger? A: Make sure you clicked "Trust This Computer" on the iPhone. Re-run bash install.sh to re-register launchd. Check cat /tmp/iphone_backup_monitor.status.

Q: Same video backed up twice? A: v3 uses content-hash dedup (first/last 512KB + file size → SHA1). The hash index lives at ~/.iphone_video_backup_v3.hashes.

Q: install.sh exits and says config still has placeholders? A: Edit config.sh first. YourExternalDrive is a sample name; install will not register launchd until BACKUP_ROOT and PHOTO_BACKUP_ROOT point at a real path.

Q: External drive wasn't mounted, backup failed? A: The script notifies you and exits without creating a fake directory under /Volumes. Mount the disk and re-run:

bash backup_videos_v3.sh
bash backup_photos_v3.sh

Q: How to uninstall auto-trigger?

bash uninstall.sh

This only removes the launchd config. Scripts, backup data, and hash indexes are untouched.

Uninstall

bash uninstall.sh

To wipe indexes only (backup files stay):

rm -f ~/.iphone_video_backup_v3.hashes ~/.iphone_photo_backup_v3.hashes
rm -f ~/.iphone_video_backup_v3.device_seen ~/.iphone_photo_backup_v3.device_seen
rm -f ~/.iphone_video_backup_v3.state ~/.iphone_photo_backup_v3.state

To delete backup files, use the paths from your config.sh — do not copy the placeholder /Volumes/YourExternalDrive/....

Contributing

Contributions welcome! See CONTRIBUTING.md.

License

MIT


中文文档

iPhone 插入 Mac 时自动备份视频和照片到外置硬盘,按 EXIF 拍摄日期归档,内容哈希精确去重,零云依赖。

特性

  • 自动触发:iPhone 插入 USB 即自动备份,无需手动操作
  • 内容哈希去重:首尾 512KB + 文件大小 → SHA1,同一内容不会重复备份
  • 按拍摄日期归档:读取 EXIF CreateDate,自动按 YYYY-MM-DD 分文件夹
  • 照片智能分类:自动区分相机照片 / 截图 / 保存的图片,分目录存放
  • 增量预筛:设备路径+文件大小未变 → 跳过下载,秒过已有文件
  • 完整性校验:AFC 下载后比对设备侧文件大小,截断自动重试
  • 防睡眠:备份期间阻止 Mac 休眠
  • 桌面通知:备份开始/完成/异常均推送 macOS 通知

快速开始

git clone https://github.com/andersyin/iphone-auto-backup.git
cd iphone-auto-backup
nano config.sh     # 必须先改路径;install 会拒绝 YourExternalDrive 占位名
bash install.sh    # 自动安装依赖 + 注册 launchd(Apple Silicon / Intel Homebrew 均可)

插入 iPhone → 解锁并点击「信任此电脑」→ 确认外置盘已挂载 → 自动开始备份。 查看状态:cat /tmp/iphone_backup_monitor.status

配置说明

参数 说明 默认值
BACKUP_ROOT 视频备份目标路径 /Volumes/YourExternalDrive/iPhone_Videos
PHOTO_BACKUP_ROOT 照片备份目标路径 /Volumes/YourExternalDrive/iPhone_Photos
VIDEO_EXTENSIONS 支持的视频格式 MOV MP4 M4V 3GP AVI MKV
PHOTO_EXTENSIONS 支持的照片格式 JPG JPEG HEIC PNG GIF
AUTO_REFRESH_INDEX 备份后跑可选的 refresh_index.sh(本仓库不附带) 0(关闭)

依赖

工具 用途 安装方式
libimobiledevice iPhone 通信协议 brew install libimobiledevice
exiftool 读取拍摄日期 brew install exiftool

常见问题

Q: 备份没有自动触发? A: 确认 iPhone 已点击「信任此电脑」;重新运行 bash install.sh;检查 cat /tmp/iphone_backup_monitor.status

Q: 重复备份同一个视频? A: v3 使用内容哈希去重,哈希索引位于 ~/.iphone_video_backup_v3.hashes

Q: 安装时报占位路径? A: 先改 config.sh 里的 BACKUP_ROOT / PHOTO_BACKUP_ROOT,再运行 bash install.sh

Q: 怎么卸载?

bash uninstall.sh

If this tool saved your photos, consider giving it a ⭐

Report a bug · Request a feature · Contributing


You might also like

  • restic-backup-toolkit — 3-tier macOS backup: rsync mirror + restic cold backup + SHA256 audit
  • md-reader — Zero-dependency single-file HTML markdown reader, 77KB, no install

Star History

About

Auto-backup iPhone photos & videos to external drive on USB plug-in. EXIF date archiving, content-hash dedup, launchd daemon, zero cloud. macOS + libimobiledevice.

Topics

Resources

Contributing

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages