How to prevent a scheduled shell script containing an rsync command from causing a kernel panic

kernel-panic

I have a simple backup shell script that runs daily at 1:00 AM. It uses rsync to copy twelve different directories onto my Windows computer's external hard drive. Here's an example:

rsync -a --delete-after --progress --stats "$HOME/Downloads" "/Volumes/Backups/MacBook Pro"

It used to work fine, but one day it kernel panicked. Then the next day. And then the next. I did some troubleshooting and found that the kernel panic only occurs when the "$HOME/Documents" directory is included in the list of directories to be backed up. But here's the bizarre thing: if I run the backup script manually, the script makes it all the way through without a kernel panic. Any ideas? Here's the report:

Sat Jun 23 01:05:10 2012
panic(cpu 4 caller 0xffffff80002c473a): Kernel trap at 0xffffff7f8081a348, type 14=page fault, registers:
CR0: 0x000000008001003b, CR2: 0xffffff802216a000, CR3: 0x00000001c4fd3077, CR4: 0x00000000000606e0
RAX: 0x0000000000000067, RBX: 0xffffff802216005c, RCX: 0xffffff801dee780a, RDX: 0x0000000000000000
RSP: 0xffffff80f05cbb60, RBP: 0xffffff80f05cbbc0, RSI: 0x0000000000000001, RDI: 0xffffff8022169fcc
R8:  0x0000000000000000, R9:  0x0000000000000000, R10: 0x80000001c4fd3077, R11: 0xffffff8023ffc800
R12: 0xffffff802216a000, R13: 0x0000000000000002, R14: 0x000000000000805c, R15: 0x0000000000000034
RFL: 0x0000000000010296, RIP: 0xffffff7f8081a348, CS:  0x0000000000000008, SS:  0x0000000000000010
CR2: 0xffffff802216a000, Error code: 0x0000000000000000, Faulting CPU: 0x4

Backtrace (CPU 4), Frame : Return Address
0xffffff80f05cb810 : 0xffffff8000220792 
0xffffff80f05cb890 : 0xffffff80002c473a 
0xffffff80f05cba40 : 0xffffff80002da0cd 
0xffffff80f05cba60 : 0xffffff7f8081a348 
0xffffff80f05cbbc0 : 0xffffff7f807fd83b 
0xffffff80f05cbc60 : 0xffffff7f807fd8fe 
0xffffff80f05cbcc0 : 0xffffff7f80804bd9 
0xffffff80f05cbd00 : 0xffffff80003192d0 
0xffffff80f05cbd30 : 0xffffff8000308911 
0xffffff80f05cbf50 : 0xffffff80005cd61b 
0xffffff80f05cbfb0 : 0xffffff80002daa13 
      Kernel Extensions in backtrace:
         com.apple.filesystems.smbfs(1.7.2)[82526DF2-3BDB-3898-BA94-F58C5D4E0E01]@0xffffff7f807f2000->0xffffff7f80826fff
            dependency: com.apple.kext.triggers(1.0)[B7CEC019-EA05-3FCB-9E1A-F1CB4A0B2669]@0xffffff7f807ed000

BSD process name corresponding to current thread: rsync

Mac OS version:
11E53

Kernel version:
Darwin Kernel Version 11.4.0: Mon Apr  9 19:32:15 PDT 2012; root:xnu-1699.26.8~1/RELEASE_X86_64
Kernel UUID: A8ED611D-FB0F-3729-8392-E7A32C5E7D74
System model name: MacBookPro8,2 (Mac-94245A3940C91C80)

System uptime in nanoseconds: 252434098601163
last loaded kext at 236423088215259: net.tunnelblick.tun    1.0 (addr 0xffffff7f80791000, size 32768)
last unloaded kext at 236897483051934: net.tunnelblick.tun  1.0 (addr 0xffffff7f80791000, size 24576)
loaded kexts:
org.virtualbox.kext.VBoxNetAdp  4.1.10
org.virtualbox.kext.VBoxNetFlt  4.1.10
org.virtualbox.kext.VBoxUSB 4.1.10
org.virtualbox.kext.VBoxDrv 4.1.10
com.apple.filesystems.smbfs 1.7.2
com.apple.driver.AppleHWSensor  1.9.5d0
com.apple.driver.AudioAUUC  1.59
com.apple.driver.AppleMikeyHIDDriver    122
com.apple.driver.AppleUpstreamUserClient    3.5.9
com.apple.driver.AppleMCCSControl   1.0.26
com.apple.driver.AppleHDA   2.2.0f3
com.apple.driver.AppleMikeyDriver   2.2.0f3
com.apple.driver.AppleIntelHD3000Graphics   7.1.8
com.apple.driver.AGPM   100.12.42
com.apple.kext.ATIFramebuffer   7.1.8
com.apple.driver.SMCMotionSensor    3.0.2d6
com.apple.driver.AppleSMCPDRC   5.0.0d0
com.apple.iokit.IOUserEthernet  1.0.0d1
com.apple.iokit.IOBluetoothSerialManager    4.0.5f11
com.apple.Dont_Steal_Mac_OS_X   7.0.0
com.apple.driver.AudioIPCDriver 1.2.2
com.apple.driver.AppleSMCLMU    2.0.1d2
com.apple.driver.AppleMuxControl    3.0.16
com.apple.driver.ACPI_SMC_PlatformPlugin    5.0.0d0
com.apple.ATIRadeonX3000    7.1.8
com.apple.driver.AppleLPC   1.5.8
com.apple.filesystems.autofs    3.0
com.apple.driver.BroadcomUSBBluetoothHCIController  4.0.5f11
com.apple.driver.AppleUSBTCButtons  225.2
com.apple.driver.AppleUSBTCKeyboard 225.2
com.apple.driver.AppleIRController  312
com.apple.AppleFSCompression.AppleFSCompressionTypeDataless 1.0.0d1
com.apple.AppleFSCompression.AppleFSCompressionTypeZlib 1.0.0d1
com.apple.BootCache 33
com.apple.iokit.SCSITaskUserClient  3.2.0
com.apple.driver.XsanFilter 404
com.apple.iokit.IOAHCISerialATAPI   2.0.3
com.apple.iokit.IOAHCIBlockStorage  2.0.3
com.apple.driver.AppleSDXC  1.2.0
com.apple.driver.AppleUSBHub    4.5.0
com.apple.driver.AppleFWOHCI    4.8.9
com.apple.driver.AirPort.Brcm4331   530.4.20
com.apple.iokit.AppleBCM5701Ethernet    3.1.2b2
com.apple.driver.AppleEFINVRAM  1.5.0
com.apple.driver.AppleAHCIPort  2.3.0
com.apple.driver.AppleSmartBatteryManager   161.0.0
com.apple.driver.AppleUSBEHCI   4.5.8
com.apple.driver.AppleACPIButtons   1.5
com.apple.driver.AppleRTC   1.5
com.apple.driver.AppleHPET  1.6
com.apple.driver.AppleSMBIOS    1.8
com.apple.driver.AppleACPIEC    1.5
com.apple.driver.AppleAPIC  1.5
com.apple.driver.AppleIntelCPUPowerManagementClient 193.0.0
com.apple.nke.applicationfirewall   3.2.30
com.apple.security.quarantine   1.3
com.apple.driver.AppleIntelCPUPowerManagement   193.0.0
com.apple.driver.DspFuncLib 2.2.0f3
com.apple.driver.AppleSMBusController   1.0.10d0
com.apple.iokit.IOSurface   80.0.2
com.apple.iokit.IOSerialFamily  10.0.5
com.apple.iokit.IOFireWireIP    2.2.4
com.apple.iokit.IOAudioFamily   1.8.6fc17
com.apple.kext.OSvKernDSPLib    1.3
com.apple.driver.AppleHDAController 2.2.0f3
com.apple.iokit.IOHDAFamily 2.2.0f3
com.apple.driver.ApplePolicyControl 3.0.16
com.apple.driver.AppleGraphicsControl   3.0.16
com.apple.driver.AppleSMC   3.1.3d8
com.apple.driver.IOPlatformPluginLegacy 5.0.0d0
com.apple.driver.AppleSMBusPCI  1.0.10d0
com.apple.driver.IOPlatformPluginFamily 5.1.0d17
com.apple.driver.AppleBacklightExpert   1.0.3
com.apple.iokit.IONDRVSupport   2.3.2
com.apple.kext.triggers 1.0
com.apple.kext.ATI6000Controller    7.1.8
com.apple.kext.ATISupport   7.1.8
com.apple.driver.AppleIntelSNBGraphicsFB    7.1.8
com.apple.iokit.IOGraphicsFamily    2.3.2
com.apple.driver.AppleUSBBluetoothHCIController 4.0.5f11
com.apple.iokit.IOBluetoothFamily   4.0.5f11
com.apple.driver.AppleThunderboltDPInAdapter    1.8.2
com.apple.driver.AppleThunderboltDPAdapterFamily    1.8.2
com.apple.driver.AppleThunderboltPCIDownAdapter 1.2.4
com.apple.driver.AppleUSBMultitouch 227.1
com.apple.iokit.IOUSBHIDDriver  4.4.5
com.apple.driver.AppleUSBMergeNub   4.5.3
com.apple.driver.AppleUSBComposite  4.5.8
com.apple.driver.CoreStorage    182.11.0
com.apple.iokit.IOSCSIMultimediaCommandsDevice  3.2.0
com.apple.iokit.IOBDStorageFamily   1.6
com.apple.iokit.IODVDStorageFamily  1.7
com.apple.iokit.IOCDStorageFamily   1.7
com.apple.iokit.IOSCSIArchitectureModelFamily   3.2.0
com.apple.driver.AppleThunderboltNHI    1.5.5
com.apple.iokit.IOThunderboltFamily 2.0.0
com.apple.iokit.IOUSBUserClient 4.5.8
com.apple.iokit.IOFireWireFamily    4.4.5
com.apple.iokit.IO80211Family   420.3
com.apple.iokit.IOEthernetAVBController 1.0.1b1
com.apple.iokit.IONetworkingFamily  2.1
com.apple.iokit.IOAHCIFamily    2.0.8
com.apple.iokit.IOUSBFamily 4.5.8
com.apple.driver.AppleEFIRuntime    1.5.0
com.apple.iokit.IOHIDFamily 1.7.1
com.apple.iokit.IOSMBusFamily   1.1
com.apple.security.sandbox  177.5
com.apple.kext.AppleMatch   1.0.0d1
com.apple.security.TMSafetyNet  7
com.apple.driver.DiskImages 331.6
com.apple.iokit.IOStorageFamily 1.7.1
com.apple.driver.AppleKeyStore  28.18
com.apple.driver.AppleACPIPlatform  1.5
com.apple.iokit.IOPCIFamily 2.6.8
com.apple.iokit.IOACPIFamily    1.4

EDIT: Here is the shell script I'm running:

#!/bin/bash

target_directory="/Volumes/Backups/MacBook Pro"

directories_to_back_up=(
    "$HOME/Desktop"
    "$HOME/Documents"
    "$HOME/Downloads"
    "$HOME/Pictures/Photo Booth Library"
    "$HOME/.filezilla"
    "$HOME/Library/Application Support/Firefox"
    "$HOME/Library/Application Support/TextMate"
    "$HOME/Library/Mail"
    "$HOME/Library/Preferences"
    "/Applications/MAMP/conf"
    "/Applications/MAMP/htdocs"
);

if [ -d "$target_directory" ]; then
    for directory in "${directories_to_back_up[@]}"
    do
        if [ -d "$directory" ]; then
            echo "The following backup will begin in 10 seconds:"
            echo
            echo "Source: \"$directory\""
            echo "Target: \"$target_directory\""
            sleep 10
            echo

            rsync -a --delete-after --progress --stats "$directory" "$target_directory"
        else
            echo "The following directory was not found:"
            echo
            echo "\"$directory\""
            echo
            echo "Therefore, it was not backed up."
        fi

        echo
        echo "----------------------------------------"
        echo
    done
else
    echo "The backup could not proceed because the following directory was not found:"
    echo
    echo "\"$target_directory\""
fi

Best Answer

I notice you have VirtualBox kexts loaded. I assume you have a VM running during the backup. In the past few months I've had kernel panics (nowhere near consistent as yours), from varying apps, but I eventually realized they only happen if I have VMs running and a high CPU load (like rsync would create).

I have no idea why yet, but you could probably test that on your system.

Your rsync command looks OK. I second the comment that says you should use launchd rather than cron though. Cleaner, more reliable, and once you create the plist in the right place, you won't have to worry about accidentally running as root.

There's a nice app called Lingon that provides a GUI for launchd. Very nice to work with, even if you're comfortable editing plist files manually.

Also, make sure the shell you specify at the top of the script is the same as the shell you're using in Terminal. Doubtful that's it, but you never know.