This script mounts an iPhone, copies the DCIM folder into a dated backup, optionally calculates file hashes, deletes old photos from the device (based on a cutoff date), removes empty DCIM directories, and generates an HTML report + log. It supports a dry-run mode to preview deletions.
bash(the script is a bash script)ifuse(to mount the iPhone)rsync(for copying files)sha256sum(recommended; used to update the hash DB)exiftool(optional; used to read EXIF dates for better precision)google-chromeorgoogle-chrome-stable(optional; used to auto-open the HTML report)sudoaccess for mount/unmount and deletion operations
You can now pass options directly via command line:
--dry-run— preview changes without deleting files or creating archive.--cores N— set number of parallel workers (default: 4).--help— show usage help.
For settings not exposed as CLI flags, edit the script directly:
MOUNT_POINT— where the phone is mounted (e.g./media/pete/New Volume/iphone).BACKUP_ROOT— root path where backups, reports, logs, and temporary dirs are stored.CUTOFF_DATE_IPHONE— numeric epoch cutoff used to select files to delete (script sets to 12 months ago by default).HASH_DB,TMP_BACKUP_DIR,ARCHIVE_NAME,REPORT_FILE,DELETED_FILES_LIST,LOG_FILE— paths derived fromBACKUP_ROOT.
- Make the script executable (if not already):
chmod +x iphone_backup.sh- Run the script with optional flags (you will be prompted for
sudowhere needed):
./iphone_backup.sh- Test with a dry run:
./iphone_backup.sh --dry-run- Run with custom parallelism:
./iphone_backup.sh --cores 3- Combine flags:
./iphone_backup.sh --dry-run --cores 3- To change deletion age, edit the
CUTOFF_DATE_IPHONEassignment (e.g. usedate -d "6 months ago" +%s). - Use
--cores Nto adjust parallelism based on your CPU (e.g.--cores 4for faster hashing/deletions). - If you want EXIF-based timestamps for deletion, install
exiftool; the script auto-detects it. - The script appends logs to
LOG_FILEand records deleted/dry-run items inDELETED_FILES_LIST. - The script will automatically unmount the iPhone on exit (normal or interrupted).
- If required dependencies are missing, the script will report them and exit with code 1.
- Always run a dry run first (
--dry-runflag) to verify which files would be deleted. - Ensure
MOUNT_POINTandBACKUP_ROOTare accessible and have sufficient free space. - If the
DCIMfolder is not found, check thatifusemounted the device successfully and that the phone is unlocked/trusted. - If Chrome doesn't open automatically, open the generated HTML report at the path printed in the log.
- If you press Ctrl+C during execution, the script will gracefully unmount the iPhone before exiting.
- Full backup + cleanup (interactive sudo prompts as needed):
./iphone_backup.sh- Dry run (preview deletions, no archive):
./iphone_backup.sh --dry-run- Dry run with increased parallelism:
./iphone_backup.sh --dry-run --cores 4- Run with custom core count (for faster performance on high-CPU systems):
./iphone_backup.sh --cores 16- Show help:
./iphone_backup.sh --helpSee the project LICENSE file for licensing details.
For bug reports or feature requests, open an issue in your project tracker.