One of the things you’ll love about your Mac – especially if you have recently switched from Windows – is Time Machine, the built-in backup feature. To use it you’ll need an external storage solution such as an external hard drive (or SSD) connected via the USB, Thunderbolt or FireWire port on your Mac, the Time Capsule or macOS server on your network, or the external hard drive connected to the AirPort Extreme base stations on your network. It is recommended that you back up before every major action, but as you start using the feature you’ll see that you don’t really need to back up your Mac on a daily basis. But that, of course, varies by user.
Time Machine has its own scripts for housekeeping, but sometimes (such as when you see the “Time Machine could not complete the backup” error message) you may need to intervene to clean up space on your Time Machine drive. Space can always be saved on your backup if you delete junk, cache and temporary files before you back up the computer. That’s particularly true if you haven’t set up any exceptions in Time Machine preferences, and everything is saved, even applications.
Since every external storage device has its own physical limits, if you are going to keep that drive in the long run then it’s good to optimize your backups so that they occupy less space. For that it is possible to compress Time Machine backups, but before you start deleting and compressing backups you need to understand how Time Machine works.
Time Machine uses File System Event Store, a hidden log macOS keeps of changes made to the data on each HFS+ formatted drive or partition. But this won’t list every file that has changed; instead, it will list the directories affected. Time Machine uses this log to find out what’s changed and what needs to be backed up.
When Time Machine does the first backup, it copies everything (except trash and system work files) and creates a dated backup folder (year-month-day-hhmmss) in the Backups.backupdb folder, placing hard links in it to all the backup copies it has just made. Another dated backup folder is then created with the second backup, and this repeats each time. There is a trick, however: the second backup folder contains hard links to the items that remained unchanged.
There are notable differences between the normal (or local) Backups.backupdb folder and a backup made over a network. Local backups are stored in a single Backups.backupdb folder at the top level of the external hard drive.
If you are backing up your Mac over a network (be it wired or wireless), you’ll find the Backups.backupdb folder inside a container called a “sparse bundle disk image”. While it works just as well as the local backup version, an extra step is needed to actually recoup the space gained by deleting earlier backups due to its format. Unlike a normal folder or disk image, when you delete a file in a sparse bundle, it won’t change the container size. To recoup the space, run the following command in Terminal (replacing the ‘Yourbackup’ entry with the necessary backup name):
% sudo su - root
% hdiutil compact /Volumes/TimeMachine/YourBackup.sparsebundle
What you’ll then see is:
Starting to compact…
Reclaiming free space…
……………………………………………
Finishing compaction…
Reclaimed X.X GB out of XXX.X GB possible.
Enter Time Machine.
Navigate to the backup you want to remove.
Right-click on the backup in the Finder window of Time Machine, and select Delete Backup.
Time Machine will prompt for the admin password and then delete the required file.
That’s a bit clumsy if you want to delete multiple backups, so here’s a Terminal command for this, which is very useful when deleting old backups:
tmutil delete /TimeMachine/Drive/Path/To/OldBackup/
Or, if you want to remove a backup from a specific date:
tmutil delete /Volumes/BackupDriveName/Backups.backupdb/MacComputerName/YYYY-MM-DD-HHMMSS/
If you don’t mind speaking with your Mac via Terminal commands, then it’s even possible to automate the removal of old Time Machine backups by running the following batch script. Note that this will find the oldest and newest backups and display a prompt to delete the oldest, which then requires you to enter “Y” and the admin password to finish.
COMPUTER_NAME=$(/usr/sbin/scutil --get ComputerName)
NBACKUPS=$(/usr/bin/tmutil listbackups |
/usr/bin/grep "$COMPUTER_NAME" |
/usr/bin/wc -l)
OLDEST_BACKUP=$(/usr/bin/tmutil listbackups |
/usr/bin/grep "$COMPUTER_NAME" |
/usr/bin/head -n1)
LATEST_BACKUP=$(/usr/bin/tmutil latestbackup)
echo Latest backup: $LATEST_BACKUP
if [[ -n "$LATEST_BACKUP" && "$LATEST_BACKUP" != "$OLDEST_BACKUP" ]] then
echo -n "$NBACKUPS backups. Delete oldest: ${OLDEST_BACKUP##*/} [y/N]? "
read answer
case $answer in
y*)
echo Running: /usr/bin/sudo /usr/bin/tmutil delete "$OLDEST_BACKUP"
/usr/bin/sudo time /usr/bin/tmutil delete "$OLDEST_BACKUP"
;;
*)
echo No change
;;
esac
else
echo "No backup available for deletion"
fi
Best Reviews may receive compensation for its content through paid collaborations and/or affiliate links. Learn more about how we sustain our work and review products.
©2012-2024 Best Reviews, a clovio brand –
All rights
reserved
Privacy
policy
·
Cookie
policy
·
Terms
of use
·
Partnerships
· Contact
us