如何防止包含rsync命令的计划shell脚本导致内核崩溃?


3

我有一个简单的备份shell脚本,每天凌晨1点运行。它使用rsync将12个不同的目录复制到我的Windows计算机的外部硬盘上。这是一个例子:

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

它过去工作正常,但有一天内核恐慌。然后第二天。然后是下一个。我做了一些故障排除,发现仅当“$ HOME / Documents”目录包含在要备份的目录列表中时才会发生内核崩溃。但这是奇怪的事情:如果我手动运行备份脚本,脚本会在没有内核恐慌的情况下完成整个过程。有任何想法吗?这是报告:

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

编辑 :这是我正在运行的shell脚本:

#!/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

如何调用脚本,1。手动,2。按计划?换句话说,使用哪个确切的命令来启动,以及如何安排运行脚本?
Pro Backup

@ProBackup这只是一个cron工作: 0 1 * * * /Users/Nick/Documents/backup.sh。我使用相同的命令手动运行它。
Nick

backup.sh文件的内容是什么?为什么在launchd中使用cron是OS X(至少从10.6开始)启动计划任务的首选机制?
Pro Backup

1
我将开始尝试使用用户守护程序作业通过launchd启动脚本。创建plist文件。即使没有用户登录就需要运行作业时将其放入 /Library/LaunchDaemons/。二, $ sudo launchctl load -w /Library/LaunchDaemons/my.scheduled.backup.plist。有一个很好的plist cron风格的例子 apple.stackexchange.com/questions/820/... 注意:在编辑plist之前,请先卸载它。然后在编辑完成后再次加载它。
Pro Backup

1
对不起,我无法回答,不得不再问一个问题。您的cron(作业)在哪个用户帐户下运行?很可能是root用户,但可以肯定的是,这就是为什么在运行cron作业和从shell运行脚本交互之间存在差异。
Pro Backup

Answers:


1

我注意到你加载了VirtualBox kexts。我假设您在备份期间运行了VM。在过去的几个月里,我遇到了内核恐慌(与你的不一样),来自不同的应用程序,但我最终意识到只有当我运行VM并且CPU负载很高(如rsync会创建)时才会发生这种情况。

我不知道为什么,但你可以在你的系统上测试它。

您的rsync命令看起来没问题。我说你应该使用的评论 launchd 而不是 cron 虽然。更清洁,更可靠,一旦您在正确的位置创建了plist,您就不必担心意外地以root身份运行。

有一个很好的应用程序叫 Lingon 为...提供GUI launchd。非常好用,即使你很乐意手动编辑plist文件。

此外,请确保您在脚本顶部指定的shell与您在终端中使用的shell相同。令人怀疑的是,但你永远不知道。


我实际上在备份期间没有运行任何虚拟机。我之前没有使用过launchd,但是,为了实验,我注释掉了我的cron作业,将一个plist文件放在〜/ Library / LaunchAgents中,并用launchctl加载它。我们会看到会发生什么。我会报告回来。谢谢你的时间!
Nick

通过launchd运行脚本并没有发挥任何作用。我最后通过删除一个充满图标的文件夹来解决问题(我认为大约有18,000个或类似的东西)。我认为图标本身没有任何问题导致问题。我认为这只是rsync处理这么多文件的事实。但是,这种情况似乎很奇怪。还有其他想法吗?
Nick

2
回溯包含 com.apple.filesystems.smbfs kext - 这是用于连接samba / windows网络共享的kext。如果备份目标是这样的网络共享,我可以想象你在Windows共享上处理超过X千个文件时发现了一个错误。
pmdj

@pmjordan该理论的唯一缺陷是手动运行时脚本运行良好
Nick
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.