mac catalina tar 在 launchctl 上出现错误,但从终端运行脚本时却没有错误

mac catalina tar 在 launchctl 上出现错误,但从终端运行脚本时却没有错误

使用 launchctl 对桌面文件夹进行皮重处理时出现错误。

编辑:此错误仅发生在某些文件夹(即桌面)上。它在其他文件夹(即/etc)上运行良好。下面的 test.sh 脚本仅在桌面上运行 tar 命令。我的备份才是真正的问题所在,它包含许多不同的目录。它似乎也是在升级到 Catalina 操作系统后启动的。

tar:无法打包扩展属性:不允许操作
tar:从成员名称 a Users/davidk/Desktop 中删除前导“/”
tar:/Users/davidk/Desktop:无法访问目录:未知错误:-1
tar:错误由于先前的错误而延迟退出。

我认为这与安全有关。我已尝试对 launchctl 和 bsdtar 提供完整磁盘访问权限,但仍然出现错误。

我的清单:

more /Library/LaunchDaemons/test.plist 
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
        <key>Label</key>
        <string>test</string>
        <key>ProgramArguments</key>
        <array>
                <string>/etc/cron.daily/test.sh</string>
        </array>
        <key>StandardOutPath</key>
        <string>/var/log/test.log</string>
        <key>StandardErrorPath</key>
        <string>/var/log/test.log</string>

        <key>StartCalendarInterval</key>
        <dict>
                <key>Hour</key>
                <integer>1</integer>
                <key>Minute</key>
                <integer>1</integer>
        </dict>
        <key>ProcessType</key>
        <string>Background</string>
</dict>
</plist>
[davids-imac:cron.daily root]$ launchctl start test

结果:

backup.sh begin '11/07/2019 12:10:00'
Script executed from: /
Script location BASEDIR: /etc/cron.daily
running DAILY
 192.168.1.225:/home/backup/davids-imac.dkcc.com/Thu/  -> Should be  192.168.1.225:/home/backup/davids-imac.dkcc.com/Thu
end tests
Running! '11/07/2019 12:10:00'
12:10:00 rm /usr/local/backup/davidk-Desktop.tar.gz
12:10:00  tar /davidk/Desktop..
tar: Could not pack extended attributes: Operation not permitted
tar: Removing leading '/' from member names
a Users/davidk/Desktop
tar: /Users/davidk/Desktop: Couldn't visit directory: Unknown error: -1
tar: Error exit delayed from previous errors.
12:10:00  

tar 文件是:

-rw-r--r--  1 root  wheel         127 Nov  7 12:10 davidk-Desktop.tar.gz

但是从终端运行时:

[davids-imac:cron.daily root]$ ./test.sh 
backup.sh begin '11/07/2019 12:23:46'
Script executed from: /etc/cron.daily
Script location BASEDIR: .
running DAILY
 192.168.1.225:/home/backup/davids-imac.dkcc.com/Thu/  -> Should be  192.168.1.225:/home/backup/davids-imac.dkcc.com/Thu
end tests
Running! '11/07/2019 12:23:46'
12:23:46 rm /usr/local/backup/davidk-Desktop.tar.gz
12:23:46  tar /davidk/Desktop..
tar: Removing leading '/' from member names
12:26:17  
12:26:17  removing PID
12:26:17  Complete!
Began: '11/07/2019 12:23:46', Completed: 12:26:17

tar 文件是:

-rw-r--r--  1 root  wheel  5059085737 Nov  7 12:26 davidk-Desktop.tar.gz

编辑:添加了 test.sh ——这是一个简化的备份,但将问题隔离到 tar 命令:

[davids-imac:cron.daily root]$ more test.sh 
#!/bin/bash

START_TIME=`date +"'%m/%d/%Y %H:%M:%S'"`
PIDFILE=/var/run/dkccBackup.pid
BKUPFILE=/etc/backup/bkup.sh
LOCAL_DIR=/usr/local/backup
MONTHLY_IP=192.168.1.230
DAILY_IP=192.168.1.225
RUN_IP=" "
MDATE=" "
HOSTNAME=`hostname`

echo "backup.sh begin ${START_TIME}"
echo "Script executed from: ${PWD}"

BASEDIR=$(dirname $0)
echo "Script location BASEDIR: ${BASEDIR}"
if [ "${BASEDIR}" == "/etc/cron.daily" ] || [ "${PWD}" == "/etc/cron.daily" ]; then
   echo "running DAILY"
   RUN_IP="$DAILY_IP"
   MDATE=`date +%a`
elif [ "${BASEDIR}" == "/etc/cron.monthly" ] || [ "${PWD}" == "/etc/cron.monthly" ]; then
        echo "running MONTHLY"
   RUN_IP="$MONTHLY_IP"
   MDATE=`date +%B`
else 
        echo "Cannot determine Monthly or daily, assuming daily"
   RUN_IP="$DAILY_IP"
   MDATE=`date +%a`
fi

BACKUP_DIR="${RUN_IP}:/home/backup/${HOSTNAME}/${MDATE}"
echo " $RUN_IP:/home/backup/`hostname`/`date +%a`/  -> Should be  $BACKUP_DIR"

echo end tests

timeout=6  # timeout after 60mn  
while ((timeout > 0)) && [ -f $PIDFILE ];
do
        echo Sleeping 10 minutes `date +"'%m/%d/%Y %H:%M:%S'"` 

   sleep 1000
   ((timeout -= 1))
done 

echo Running! `date +"'%m/%d/%Y %H:%M:%S'"` 
touch $PIDFILE


echo `date +"%T"` rm $LOCAL_DIR/davidk-Desktop.tar.gz
rm -f $LOCAL_DIR/davidk-Desktop.tar.gz

echo `date +"%T"` " tar /davidk/Desktop.."
/usr/bin/tar --no-xattr -zcf $LOCAL_DIR/davidk-Desktop.tar.gz /Users/davidk/Desktop

echo `date +"%T"` " "

echo `date +"%T"` " removing PID"
rm -f $PIDFILE

echo `date +"%T"` " Complete!"
echo "Began: ${START_TIME}, Completed: `date +"%T"`"

答案1

我想到了。这是安全。

我需要提供对 /bin/bash 的完整磁盘访问权限。

系统偏好设置 -> 安全和隐私

在“隐私”选项卡下,向下滚动到“完整磁盘访问”

单击锁并输入您的密码。

打开一个新的查找器窗口并转到 /bin 文件夹。

将 bash 图标拖到“允许下面的应用程序访问数据”区域,tar 现在可以工作了。

早些时候,我还拖动了 bsdtar、launchctl、终端来允许磁盘访问。

相关内容