udev 규칙에서 백업 스크립트를 실행 중입니다. 스크립트는 rsync를 사용하여 새로 연결된 USB 드라이브에 데이터를 로드하고 복사합니다.
# Mounting stuff
MOUNTPOINT=/media/backup
export OUTPUT=/tmp/rsync-output.log
# -a does not work on exFAT partitions, because of permissions, groups, owner. Use -rltD instead of -rlptgoD, which -a would imply.
rsync -rltDv --exclude '*.app' --exclude-from=/home/gauthier/rsync-exclude.txt /home/gauthier/ $MOUNTPOINT/gauthier/ > $OUTPUT 2>&1
touch /home/gauthier/tmp/I_came_here
rsync
다음과 같이 시작됩니다 /tmp/rsync-output.log
.
gauthier@ionian:~/tmp $ tail /tmp/rsync-output.log
rsync: symlink "/media/backup/gauthier/code/wine64/loader/wine" -> "/home/sandbox/wine3264/loader/wine" failed: Function not implemented (38)
rsync: symlink "/media/backup/gauthier/code/wine64/loader/wine-preloader" -> "/home/sandbox/wine3264/loader/wine-preloader" failed: Function not implemented (38)
rsync: symlink "/media/backup/gauthier/code/wine64/po/LINGUAS" -> "../../wine/po/LINGUAS" failed: Function not implemented (38)
rsync: symlink "/media/backup/gauthier/code/wine64/tools/l_intl.nls" -> "../../wine/tools/l_intl.nls" failed: Function not implemented (38)
rsync: symlink "/media/backup/gauthier/code/wine64/tools/winegcc/winecpp" -> "winegcc" failed: Function not implemented (38)
rsync: symlink "/media/backup/gauthier/code/wine64/tools/winegcc/wineg++" -> "winegcc" failed: Function not implemented (38)
sent 30,239,649,237 bytes received 237,923 bytes 18,123,995.90 bytes/sec
total size is 206,189,220,918 speedup is 6.82
rsync error: some files/attrs were not transferred (see previous errors) (code 23) at main.c(1183) [sender=3.1.1]
/home/gauthier/tmp/I_came_here
그런데 생성해야 할 파일이 touch
존재하지 않습니다. 그 뒤에도 뭔가가 있었는데 touch
, 그것도 실행되지 않은 것 같았습니다.
rsync
오류가 있어도 반환하면 안되나요? 반품이 불가능한 이유는 무엇입니까?
bash 프롬프트에서 스크립트를 실행해 보았지만(udev 규칙이 실행되도록 하는 대신) rsync
.
전체 스크립트:
#!/bin/bash
#export DISPLAY=:0
export XAUTHORITY=~/.Xauthority
xmessage -buttons abort -default abort -center -timeout 10 "Starting backup. Press enter to abort."
ANSWER=$?
if [ $ANSWER -eq 101 ] ; then
xmessage -timeout 3 "Aborted!"
exit
fi
if [[ ! -L /dev/backup_external_hd ]] ; then
xmessage "External disk not present at /dev/backup_external_hd, aborting backup."
exit
fi
MOUNTPOINT=/media/backup
sudo mkdir -p $MOUNTPOINT
sudo mount /dev/backup_external_hd $MOUNTPOINT
if ! grep "$MOUNTPOINT" /proc/mounts ; then
xmessage "Failed to mount $MOUNTPOINT!"
rmdir $MOUNTPOINT
exit
fi
export OUTPUT=/tmp/rsync-output.log
# -a does not work on exFAT partitions, because of permissions, groups, owner. Use -rltD instead of -rlptgoD, which -a would imply.
rsync -rltDv --exclude '*.app' --exclude-from=/home/gauthier/rsync-exclude.txt /home/gauthier/ $MOUNTPOINT/gauthier/ > $OUTPUT 2>&1
touch /home/gauthier/tmp/I_came_here
xmessage "AAAAyyye"
# Pop up a result window
# Get a summary
export RESULT_MESSAGE=/tmp/rsync-result.txt
echo "Backup result:" > $RESULT_MESSAGE
echo "" >> $RESULT_MESSAGE # \n does not seem to work in echo strings
tail -3 $OUTPUT >> $RESULT_MESSAGE
echo "" >> $RESULT_MESSAGE
echo "" >> $RESULT_MESSAGE
echo "Details in $OUTPUT" >> $RESULT_MESSAGE
xmessage -file $RESULT_MESSAGE
# Apparently unmounting too fast after writing could be a problem.
sleep 1
sudo umount $MOUNTPOINT
if grep "$MOUNTPOINT" /proc/mounts ; then
xmessage "Could not unmount $MOUNTPOINT."
exit
fi
sudo rmdir $MOUNTPOINT