Monday, March 30, 2020

How to compress your Time Machine backups that is on a network shared drive?

Compacting Time Machine File that is on a network shared drive. Do this after deleting the old backups from your time machine backups to reclaim the space the previous backups occupied.


  1. Dismount your time machine disk from Time Machine preference by selecting Remove Disk under Select Disk menu.

This is important to ensure nothing is accessing your time machine backup file. Else you will receive the "hdiutil resource temporarily unavailable" error when running the compact command. 

  1. To avoid the “hdiutil compact internal” error, ensure that the sparsebundle or your MAC backup file is not being accessed by anyone or anything. To do this, access the sparsebundle file in your NAS drive via Finder and mount it by clicking on it. Once it appears in your Finder  under Devices eject it manually. 

Sometimes it takes quite a few minutes (20-30 mins) for the sparsebundle file to be mounted after you click on it before you can eject it. If this happens, check the /var/log/fsck_hfs.log file and see if the mac is running fsck on the disk. Once its done, a window might appear saying nothing to be mounted, don’t worry and perform step 2  again.


3.     Using your user administrator account in your mac, open your Terminal Application and switch to root.

sudo -i

<enter your admin password when asked for password>

4.     Run the command below in your MAC Terminal screen after step 3 above. You can also run 'df -k' before you run the below command to compare your file system utilisation of your mac backup drive or location.

            hdiutil compact <fullpath of your sparesebundle file>

            Example:

               hdiutil compact /Volumes/MacBackup/MyImac.sparsebundle

            If you receive a “hdiutil resource temporarily unavailable”,
·       Make sure you have done step 1 above.
·       Make sure no processes is accessing the sparsebundle file even in your NAS storage.
·       Make sure you have the location of your sparsebundle file mounted in your MAC. For the case of the above example, make sure /Volumes/Macbackup is mounted in your MAC. To check this, issue “df -k” command.

      If you receive “hdiutil compact internal error”
·       Make sure you have done step 2 above properly.

       Once that is complete, you can issue 'df -k' and you'll see that the available space in your NAS Drive has increased. Now its time to attach back the newly compacted backup back to your time machine.

1. Open your finder and access the remote location where your sparsebundle is located. DO NOT mount or click at this time the sparsebundle. This step will ensure that you have mounted properly the remote file system where your sparsebundle backup file is located.     
2.  As the user administrator of your Mac, Open your Time Machine Preference and add back the remote disk you used previously. (Select Backup Disk)
3.     Quickly stop the impending backup by unchecking the Back Up Automatically check box.

4.     Open a terminal window and switch to root via 'sudo -i' command and issue this command once you are root

tmutil inheritbackup <your sparsebundle  full path file location>


For example:
           tmutil inheritbackup  /Volumes/MacBackup/MyMac.sparsebundle
           Attaching disk image...
           ** /dev/rdisk3s2 (NO WRITE)
           Executing fsck_hfs (version hfs-407.50.6).
           QUICKCHECK ONLY; FILESYSTEM CLEAN
          Claiming disk image for machine...
          Ejecting disk image...


5.     Go back to your finder in step 1 and Click on the sparsebundle file in Finder to mount it as a Time Machine drive. Normally MacOS will mount it under /Volumes/Time Machine Backups file system


6.     Issue the commands below (modify the associated command parameter to the latest backup)

tmutil associatedisk -a / <location of your latest backup in /Volumes/Time Machine Backups>

For example:

(take note of the spaces and the “\” before them, this is to “escape” them in mac os command line. To easily paste the below location to your Terminal window, from your Finder window, drag whe Macintosh HD folder in the Terminal window and it will give you the path naming convention below with "\")

tmutil associatedisk -a / /Volumes/Time\ Machine\ Backups/Backups.backupdb/MyImac/2020-03-30-010714/Macintosh\ HD 

(you can use alternatively the quoted version of the command above)

tmutil associatedisk -a / “/Volumes/Time Machine Backups/Backups.backupdb/MyImac/2020-03-30-010714/Macintosh HD”


7.     Wait for a few minutes then issue this command to check if your backups are now associated back to your time machine or restart your MAC

tmutil listbackups


8.     Reboot your mac so that you’ll see the updated information (without the -1 in their volume names)

9.     Run your Time Machine Backup to update your backup information in the Time Machine Preference window.