Backups and disks
Time Machine from Terminal
Section titled “Time Machine from Terminal”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.
Local snapshots
Section titled “Local snapshots”The following command will disable and delete “local snapshots”:
sudo tmutil disablelocalYou can turn local snapshots back on by running:
sudo tmutil enablelocalExclude selected folders
Section titled “Exclude selected folders”sudo tmutil addexclusion ~/DownloadsThere 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:
sudo tmutil addexclusion ~/.composersudo tmutil addexclusion ~/.npmsudo tmutil addexclusion ~/Library/Developersudo tmutil addexclusion ~/Library/Containers/com.docker.docker/Data/List excluded
Section titled “List excluded”sudo mdfind "com_apple_backup_excludeItem = 'com.apple.backupd'"Time Machine stats
Section titled “Time Machine stats”tmutil listbackupsDelete local Time Machine snapshots
Section titled “Delete local Time Machine snapshots”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:
tmutil listlocalsnapshots /Then delete one by one, with follow command:
sudo tmutil deletelocalsnapshots <snapshot date>You can lists all snaphosts and deletes all of them in a loop:
for d in $(tmutil listlocalsnapshotdates | grep "-"); do sudo tmutil deletelocalsnapshots $d; doneBackup iCloud Drive with rclone
Section titled “Backup iCloud Drive with rclone”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/.
rclone sync ~/Library/Mobile\ Documents/com~apple~CloudDocs/ /Volumes/Backup/iCloudDriveBackup --copy-linksIf you need also backup of all deleted files (sync usually remove files that was delete from source) is
there --backup-dir parameter.
rclone sync ~/Library/Mobile\ Documents/com~apple~CloudDocs/ /Volumes/Backup/iCloudDriveBackup --copy-links --backup-dir="/Volumes/Backup/iCloudDriveArchive/$(date +%Y)/$(date +%F_%T)"Clean flash drive before unmount
Section titled “Clean flash drive before unmount”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..." fielse echo "Flash drive name missing"fiThen 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).