How To Set Up Time Machine

broken image


I just got a MacBook Pro running macOS Catalina for work, and I wanted to set up Time Machine backups for it to the Synology NAS in my basement so that if the laptop dies or is lost and I need to replace it, I won't have to redo all of the customizations it took me hours to set up. (I'm separately backing up my data files using Backblaze, but Backblaze doesn't back up system files and applications.)

I followed Synology's instructions for using my NAS as a Time Machine backup target, but I couldn't get the first, full backup to complete successfully after doing that. When Time Machine started to back up, it would say 'Looking for backup disk' and then say 'Preparing backup' and then stop one or two minutes later with no error message. Below, I explain what I investigating this problem, and how I ultimately solved it.

This article is probably applicable to other Macs (not just MacBook Pro) and other NAS servers (not just Synology).

How backing up to a network drive works

All of these steps need to complete for the first, full Time Machine backup to a network share to succeed:

Apple has discontinued those products but continues to offer Time Machine in macOS X Mojave. Why use Time Machine? The big advantage of Time Machine on a Mac is integration, as both macOS and Time Machine backup grew up together. Once you set it up it is automatic, it keeps hourly, daily and weekly updates for you. Set up your Time Capsule, your computer must meet the requirements listed below. Note: To use your Time Capsule with Time Machine in Mac OS X Leopard, you need to use Mac OS X v10.5.2 or later. AirPort Utility AirPort Utility helps you set up your Time Capsule to create a wireless network. You can create a dedicated time machine backup user to limit access to the share. Add Shared Folder to Time Machine. Open up Time Machine preferences in Systems Preferences. Click on 'Add or Remove Backup Disk' The 'timemachine' disk should be in the 'available disks' list. Enter username and password to use to connect to the file. To use Time Machine on macOS with a QNAP NAS via SMB, follow these steps. Enable Time Machine support on the NAS. Go to Hybrid Backup Sync Backup Server Time Machine Time Machine Support. Select Enable Time Machine support. Specify a password. Select a volume. Specify a capacity. Configure the SMB protocol.

  1. Mount the share. If you run the 'mount' command in a Terminal window or open Disk Utility you will see it mounted.
  2. Create a 'sparse bundle' on the network share to hold the backup. Basically, this is a disk image stored on the network share that can be mounted as a separate filesystem. Initially the sparse bundle is created with a random name (I think), but after it's successfully created it's renamed to contain the host name of the computer being backed up.
  3. Unmount the network share and mount the sparse bundle directly.
  4. Write all the backup data to the mounted sparse bundle.
  5. Unmount the sparse bundle.

What was going wrong

TL;DR It's the WiFi, dammit.

I kept running the backup. It kept failing part of the way through step 2, i.e., creating the sparse bundle. I know this because I was watching the file share in which the sparse bundle is stored, and each time the backup ran it deleted and recreated the sparse bundle from scratch, and each time it exited prematurely the sparse bundle was a different size.

Eventually Time Machine did manage to successfully create and rename the sparse bundle, but then after that it once again stopped prematurely a couple of minutes into writing the backup data. Each time I restarted the backup it would write a little more data and then stop prematurely.

To diagnose this further, I ran a ping command in a Terminal window while the backup was running, pinging the NAS. Here's what I saw immediately before the backup failed:

One of two things was happening: either the NAS was briefly becoming inaccessible to my Mac in the middle of the backup, or my Mac was briefly losing network connectivity in the middle of the backup. To determine which of these was the case, I ran the backup again, but this time rather than pinging the NAS during the backup, I pinged another machine on the network. I saw the same brief interruption, which proved that it was the Mac, not the NAS, that's losing network connectivity briefly during the backup.

This is not surprising, since if you spend some time Googling, you will discover that there are a lot of complaints online about Macs intermittently dropping their WiFi connections briefly. No one really has a good explanation for why this happens or how to fix it. It appears that this is just a widespread problem in Mac WiFi support that Apple hasn't prioritized fixing.

Unfortunately, the AFP over TCP network filesystem protocol code in the Mac kernel is apparently extremely sensitive to brief interruptions in network connectivity and incapable of recovering from brief network connections. Therefore, every time this WiFi blip happens, Time Machine gets back a filesystem error from the kernel and aborts the backup.

How I fixed it

At a high level, here's what I did to fix this:

  1. Mount the network file share with a 'hard mount' so that brief network interruptions won't cause Time Machine to freak out.
  2. Create a sparse bundle manually on the mounted network file share rather than letting Time Machine do it.
  3. Mount the sparse bundle.
  4. Tell Time Machine to use the sparse bundle as its backup location.
  5. Set up a launch agent task to mount the network file share and sparse bundle automatically every time I log in.

Hard-mounting the network file share

The key here is the -k argument to mount_afp, which is what specifies a hard mount.

Creating the sparse bundle

  1. Open Disk Utility.
  2. Select File | New Image | Blank Image…
  3. Open the folder ~/Mountpoints/TimeMachineBackups or wherever you mounted the network file share.
  4. Enter the name you want to save the bundle as in the 'Save as' and 'Name' fields.
  5. Change the 'Image Format' field to 'sparse bundle disk image'.
  6. Change the 'Size' field to the size of your hard disk.
  7. Click 'Save'.

Mount the sparse bundle

Disk Utility will mount the sparse bundle automatically after you create it. How to install google chrome os on laptop. Click the eject button in Disk Utility to eject it, and then do something like this:

If the mounted filesystem shows up on your Desktop and you don't want it there, you can make it disappear like this:

Tell Time Machine where to back up

You may need to grant Terminal full disk access to run this command. If so, you'll see an error message in your Terminal telling you that with instructions for how to do it. I recommend turning off full disk access for terminal after it's done!

Finally, open Time Machine preferences, enable 'Back Up Automatically', enable 'SHow Time Machine in menu bar', click on Time Machine in the menu bar, select 'Back Up Now', and watch the preferences window to make sure everything is working.

Mounting everything automatically using a launch agent

I created this script as ~/scripts/mount_time_machine_backup.sh (I've obscured some sensitive details here):

I made the script mode 0700 so I wasn't exposing my network file share password to the world.

Then I put this in ~/Library/LaunchAgents/comp.jik.TimeMachineMounts.plist:

Then launchctl load ~/Library/LaunchAgents/comp.jik.TimeMachineMounts.plist, and we're done!

Warnings

My MacBook has crashed at least twice in less than a week since I set this up as described above. Judging from the stack trace that displays after reboot, it looks to me like it's crashing inside network filesystem code. In addition, each time it has crashed, Time Machine has popped up a message telling me my backup was corrupt and needed to be recreated from scratch. So while the process described above works, it cannot be said to work perfectly, apparently, because of a kernel bug in macOS.

Credits

How to set up time machine backup disk

The following pages written by other people were helpful to me in figuring out much of this, though none of them put all the pieces together quite like I have here:

  • Creating a sparse bundle, and telling Time Machine to use it using tmutil setdestination: https://kb.lsa.umich.edu/public/index.php/Backing_up_with_Time_Machine_to_network_storage_using_a_sparse_bundle
  • Running a script on login: https://stackoverflow.com/questions/6442364/running-script-upon-login-mac/13372744#13372744
  • Mounting a sparse bundle from the command line: https://apple.stackexchange.com/a/23523
  • Preventing a mounted filesystem from showing up on the Desktop: https://www.idownloadblog.com/2016/12/02/how-to-hide-mounted-volumes-from-desktop-finder/

Apple's Time Machine software made it easy to set up incremental back-ups, with one exception: network drives (more formally called network-attached storage, or NAS). Time Machine only directly supports drives formatted with Apple's HFS+J file system, and will eventually use all disk space on the drive. This page provides an illustrated guide showing how to set up Time Machine on a network drive, using a sparse bundle to emulate a smaller HFS+J drive. Click ‘show screenshot' after each instruction to see the relevant screenshot.

Suggestion: consider online back-up

For six years we used the technique described on this page to back-up the Macs at my company. In 2014 we switched to Backblaze Online Backup, who provide unlimited back-up space for both Macs and Windows PCs for $5 a month. By using an online back-up solution our back-ups are safe even if a disaster hits our building and affects both our computers and our network drives.

Preparation

1. Ensure the network drive is mounted:

1a. Click ‘Go' and then ‘Network' and double-click on your network drive. If your network drive is protected, enter your username and password.

2. Find the name of your computer on the network:

2a. Open System Preferences.

2b. Click the Sharing icon.

2c. The computer name on the network is shown below the input field, with a ‘.local' suffix which should be ignored (that is, if it shows katemorley.local then your computer's network name is katemorley).

3. Ensure Time Machine will show your NAS device:

3a. Click ‘Go' and then ‘Utilities'.

3b. Click the Terminal icon.

3c. Type defaults write com.apple.systempreferences TMShowUnsupportedNetworkVolumes 1 and press enter.

4. Find the MAC address of your computer:

How To Set Up Time Machine Icloud

4a. Type ifconfig en0 | grep ether and press enter. Your MAC address is the 17-character string consisting of six pairs of hexadecimal digits separated by colons.

Creating the sparse bundle

5. Create the sparse bundle:

5a. Type hdiutil create -size 100g -fs HFS+J -volname 'Time Machine' NAME_XXXXXXXXXXXX.sparsebundle and press enter, where NAME is the name of your computer on the network (as determined in step 2c) and XXXXXXXXXX is your MAC address (as determined in step 4a) without the colons. This will create a 100 gigabyte sparse bundle; to create a sparse bundle of a different size replace 100g with a different value.

5b. Type rsync -aE NAME_XXXXXXXXXXXX.sparsebundle /Volumes/DRIVE/. and press enter, where DRIVE is the name of your network drive. This will copy the sparse bundle to the network drive, and will take several seconds.

5c. Type rm -rf NAME_XXXXXXXXXXXX.sparsebundle and press enter. This will delete the copy of the sparse bundle on your computer. You can now close Terminal.

Restore Mac From Time Machine Backup

Setting up Time Machine

6. Select the back-up location:

6a. How to install adobe premiere pro cc 2019 crack. Click the Time Machine icon and then Open Time Machine Preferences.

How to set up time machine

The following pages written by other people were helpful to me in figuring out much of this, though none of them put all the pieces together quite like I have here:

  • Creating a sparse bundle, and telling Time Machine to use it using tmutil setdestination: https://kb.lsa.umich.edu/public/index.php/Backing_up_with_Time_Machine_to_network_storage_using_a_sparse_bundle
  • Running a script on login: https://stackoverflow.com/questions/6442364/running-script-upon-login-mac/13372744#13372744
  • Mounting a sparse bundle from the command line: https://apple.stackexchange.com/a/23523
  • Preventing a mounted filesystem from showing up on the Desktop: https://www.idownloadblog.com/2016/12/02/how-to-hide-mounted-volumes-from-desktop-finder/

Apple's Time Machine software made it easy to set up incremental back-ups, with one exception: network drives (more formally called network-attached storage, or NAS). Time Machine only directly supports drives formatted with Apple's HFS+J file system, and will eventually use all disk space on the drive. This page provides an illustrated guide showing how to set up Time Machine on a network drive, using a sparse bundle to emulate a smaller HFS+J drive. Click ‘show screenshot' after each instruction to see the relevant screenshot.

Suggestion: consider online back-up

For six years we used the technique described on this page to back-up the Macs at my company. In 2014 we switched to Backblaze Online Backup, who provide unlimited back-up space for both Macs and Windows PCs for $5 a month. By using an online back-up solution our back-ups are safe even if a disaster hits our building and affects both our computers and our network drives.

Preparation

1. Ensure the network drive is mounted:

1a. Click ‘Go' and then ‘Network' and double-click on your network drive. If your network drive is protected, enter your username and password.

2. Find the name of your computer on the network:

2a. Open System Preferences.

2b. Click the Sharing icon.

2c. The computer name on the network is shown below the input field, with a ‘.local' suffix which should be ignored (that is, if it shows katemorley.local then your computer's network name is katemorley).

3. Ensure Time Machine will show your NAS device:

3a. Click ‘Go' and then ‘Utilities'.

3b. Click the Terminal icon.

3c. Type defaults write com.apple.systempreferences TMShowUnsupportedNetworkVolumes 1 and press enter.

4. Find the MAC address of your computer:

How To Set Up Time Machine Icloud

4a. Type ifconfig en0 | grep ether and press enter. Your MAC address is the 17-character string consisting of six pairs of hexadecimal digits separated by colons.

Creating the sparse bundle

5. Create the sparse bundle:

5a. Type hdiutil create -size 100g -fs HFS+J -volname 'Time Machine' NAME_XXXXXXXXXXXX.sparsebundle and press enter, where NAME is the name of your computer on the network (as determined in step 2c) and XXXXXXXXXX is your MAC address (as determined in step 4a) without the colons. This will create a 100 gigabyte sparse bundle; to create a sparse bundle of a different size replace 100g with a different value.

5b. Type rsync -aE NAME_XXXXXXXXXXXX.sparsebundle /Volumes/DRIVE/. and press enter, where DRIVE is the name of your network drive. This will copy the sparse bundle to the network drive, and will take several seconds.

5c. Type rm -rf NAME_XXXXXXXXXXXX.sparsebundle and press enter. This will delete the copy of the sparse bundle on your computer. You can now close Terminal.

Restore Mac From Time Machine Backup

Setting up Time Machine

6. Select the back-up location:

6a. How to install adobe premiere pro cc 2019 crack. Click the Time Machine icon and then Open Time Machine Preferences.

6b. Click the Choose Backup Disk button.

6c. Select the network drive and then click the Use For Backup button. Time Machine will show the drive's full capacity, but back-ups will be limited to the size chosen in step 5a.

7. Start the back-up:

7a. Time Machine will start the back-up automatically after two minutes. Alternative, click the Time Machine icon and then Back Up Now.

7b. Time Machine will show a status of ‘Preparing…' while it determines which files to back up.

7c. After a few minutes the back-up will begin and the status will change to ‘Backing up'.

7d. While the back-up is in progress, a volume called Time Machine will be shown on the desktop. Once the back-up completes, this volume will disappear.





broken image