How to back up a folder to an external drive automatically
Time Machine is the built-in backup, and it covers the whole Mac. To copy one folder to an external drive automatically, as plain files, use a launchd job that runs rsync every day and whenever a drive is mounted (the StartOnMount key). It takes a script and a plist file. A sync app with a “when the drive is connected” schedule does the same with a preview and without Terminal.
Updated · commands run on macOS 27.2
Time Machine: the whole Mac
Time Machine backs up everything on your Mac to a drive you dedicate to it, keeps older versions, and restores files or the whole Mac. If that’s what you need, use it. It doesn’t give you a plain, browsable copy of one folder on a drive that also holds other things, such as a photo folder on the drive you take to another computer.
One folder, automatically: launchd and rsync
macOS starts background jobs with launchd. Two keys in a job’s plist matter here. From man launchd.plist:
StartOnMount: “This optional key causes the job to be started every time a filesystem is mounted.”
StartCalendarInterval: “This optional key causes the job to be started every calendar interval as specified.”
Because StartOnMount fires for any disk, the script checks that your backup drive is there before copying.
- Save the script below as
~/bin/backup-photos.sh, with your own folder and drive names. - Run
zsh ~/bin/backup-photos.shonce with the drive connected and check the copy in Finder. - Save the plist below as
~/Library/LaunchAgents/local.backup-photos.plist, with your user name in the script path. - Run
launchctl bootstrap gui/$(id -u) ~/Library/LaunchAgents/local.backup-photos.plist. It runs at 21:00 and every time a disk is mounted. - Run
launchctl bootout gui/$(id -u) ~/Library/LaunchAgents/local.backup-photos.plistand delete the file.
The script and the job
~/bin/backup-photos.sh:
#!/bin/zsh
# Copy Photos 2026 to the Backup drive, if the drive is connected.
DRIVE="/Volumes/Backup"
[[ -d "$DRIVE" ]] || exit 0
rsync -a --exclude .DS_Store "$HOME/Pictures/Photos 2026/" "$DRIVE/Photos 2026/"~/Library/LaunchAgents/local.backup-photos.plist (replace you with your user name; launchd doesn’t expand ~):
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>local.backup-photos</string>
<key>ProgramArguments</key>
<array>
<string>/bin/zsh</string>
<string>/Users/you/bin/backup-photos.sh</string>
</array>
<key>StartOnMount</key>
<true/>
<key>StartCalendarInterval</key>
<dict>
<key>Hour</key>
<integer>21</integer>
<key>Minute</key>
<integer>0</integer>
</dict>
</dict>
</plist>We checked both files on macOS 27.2: the plist passes plutil -lint and the script passes zsh -n.
Things to know
- It runs blind. There’s no preview and no notification; check the drive now and then.
- No
--deletehere. This script only adds and updates. Adding--deletemakes the drive an exact copy, and deletes files on it permanently. - Privacy protection. If the folder is in Desktop, Documents or Downloads, or on a removable drive, macOS may block the background job until you allow access in System Settings › Privacy & Security.
- Only while you’re logged in. A LaunchAgent runs in your login session.
With FolderTwin
Make a pair: your folder on the left, a folder on the backup drive on the right. Choose Update (copies new and changed files, never removes anything) or Mirror (an exact copy; extras on the drive go to the Trash). Then, in Settings › Schedules, set the pair to When the drive is connected (or every hour or every day), and turn on Open at login in Settings › General.
Every sync shows the preview first, unless you turn on “Sync without asking” for that pair. Even then, a scheduled sync that would move files to the Trash asks first. Schedules run while FolderTwin is running; it can stay in the menu bar with its window closed.
Questions
Can Time Machine back up just one folder?
Not as a plain copy. Time Machine backs up the whole Mac (you can exclude folders in its options), into its own backup on a drive you give it. To have one folder as ordinary files on a drive you also use for other things, copy it with rsync or a sync app.
Does a launchd job run when I’m logged out?
A job in ~/Library/LaunchAgents runs only while you’re logged in, like any app you start.
Why did my script fail with “Operation not permitted”?
macOS protects Desktop, Documents, Downloads and removable volumes. A script started in the background may be refused access to them until you allow it in System Settings › Privacy & Security. Running the script by hand from Terminal first shows the problem quickly.
Should I add --delete to the backup?
Only if you want the drive to be an exact copy, and only after a dry run. --delete deletes files on the drive permanently; a file you deleted by mistake on the Mac disappears from the backup at the next run.
Sources
- launchd.plist(5) manual page — man launchd.plist in Terminal
- launchctl(1) manual page — man launchctl in Terminal
- rsync(1) manual page (openrsync) — man rsync in Terminal