Skip to content

Backups and disks

You can enable sudo tmutil enable or disable sudo tmutil disable from the command line. If you want to run a Time Machine backup right away, just run tmutil startbackup or tmutil stopbackup if you ever want to stop a backup.

The following command will disable and delete “local snapshots”:

Terminal window
sudo tmutil disablelocal

You can turn local snapshots back on by running:

Terminal window
sudo tmutil enablelocal
Terminal window
sudo tmutil addexclusion ~/Downloads

There is an interesting property -p that controls whether or not the folder remains in exclusion when it is moved. If you use the above command with the -p flag, then it will not be sticky.

If you are a developer there are a few quite common folders that should be excluded:

Terminal window
sudo tmutil addexclusion ~/.composer
sudo tmutil addexclusion ~/.npm
sudo tmutil addexclusion ~/Library/Developer
sudo tmutil addexclusion ~/Library/Containers/com.docker.docker/Data/
Terminal window
sudo mdfind "com_apple_backup_excludeItem = 'com.apple.backupd'"
Terminal window
tmutil listbackups

Your Time Machine backup disk might not always be available, so Time Machine also stores some of its backups on your Mac. These backups are called local snapshots. Local TimeMachine snapshots take a large amount of disk space. This space is listed as purgeable in disk info, but cannot be actually used until the system decides to free it up. You can list all local backups with:

Terminal window
tmutil listlocalsnapshots /

Then delete one by one, with follow command:

Terminal window
sudo tmutil deletelocalsnapshots <snapshot date>

You can lists all snaphosts and deletes all of them in a loop:

Terminal window
for d in $(tmutil listlocalsnapshotdates | grep "-"); do sudo tmutil deletelocalsnapshots $d; done

All iCloud drive data are located in ~/Library/Mobile\ Documents/com~apple~CloudDocs/ folder. You can easily sync them with rclone to back up hard drive connected to Mac. In my case it will be mounted to /Volumes/Backup/.

Terminal window
rclone sync ~/Library/Mobile\ Documents/com~apple~CloudDocs/ /Volumes/Backup/iCloudDriveBackup --copy-links

If you need also backup of all deleted files (sync usually remove files that was delete from source) is there --backup-dir parameter.

Terminal window
rclone sync ~/Library/Mobile\ Documents/com~apple~CloudDocs/ /Volumes/Backup/iCloudDriveBackup --copy-links
--backup-dir="/Volumes/Backup/iCloudDriveArchive/$(date +%Y)/$(date +%F_%T)"

How to clean flash drive and delete all hidden (dot) files on mac before unmount? It’s simple, save follow commands as flash:

#!/bin/bash
if [ -n "$1" ]; then
read -r -p "Clean /Volumes/$1/ and unmount? [y/N] " response
if [[ $response =~ ^([yY][eE][sS]|[yY])$ ]]; then
find /Volumes/$1/ -name '._*' -type f -delete
rm -rf /Volumes/$1/.Spotlight-V100/
rm -rf /Volumes/$1/.Trashes/
diskutil unmount /Volumes/$1/
echo "Done..."
fi
else
echo "Flash drive name missing"
fi

Then change the access mode of a file chmod +x flash. To unmount a clean flash drive just run ./flash Flashka (Flashka is name od drive).