同步后 Rsync 脚本不继续
Rsync script does not continue after sync
问题:我有一个简单的自定义备份脚本,只要检测到我的备份驱动器,它就会设置为 运行,这是通过 udev 完成的。一切都很好,直到脚本执行到一半时它似乎在 rsync 命令之后挂起。我的代码如下:
#!/bin/bash
#Mount the Backup Drive
wall "backup is starting"
mount -U f91b8373-6349-4de3-86e1-6a2557f2c3f7 /media/backupdrive
#Get updated package-list
mv /media/backupdrive/package-selections /media/backupdrive/package-selections.old
dpkg --get-selections >/media/backupdrive/package-selections
wall "pacakge list updated"
#Run Backup
mv /home/user/backup/rsync.log /home/user/backup/rsync.log.old
rsync --log-file=/media/backupdrive/backup/rsync.log -ravzX --delete --exclude /var/tmp --exclude /var/lock --exclude /var/run /home /etc /var /usr /media/backupdrive/backup
wall "rsync complete"
#Sync changes to disk and unmount
sync
cp /media/backupdrive/backup/rsync.log /home/user/backup/rsync.log
umount /media/backupdrive
wall "Backup is complete, the logfile can be viewed at /home/user/backup/rsync.log"
问题:我哪里做错了,为什么脚本在 rsync 后没有继续?
PS - 墙命令对脚本来说并不重要,我将它们放在不同的位置进行故障排除,是的,我是新手:)
编辑 - 我曾尝试删除类似问题中提到的 "z" 选项,但这没有任何区别
这就像udev中的运行命令超时。
不是直接从 udev 运行ning 备份脚本(通常需要很长时间才能完成),您可以 运行 它来自单独的进程,由 udev 激活。
例如你可以使用at
命令:
ACTION=="add", KERNEL=="sd*", ENV{ID_FS_UUID_ENC}=="f91b8373-6349-4de3-86e1-6a2557f2c3f7", RUN+="/home/steve/backup/backup_at.sh"
backup_at.sh:
#!/bin/sh
echo /home/steve/backup/backup.sh | at now
或者你可以尝试在后台运行它:
ACTION=="add", KERNEL=="sd*", ENV{ID_FS_UUID_ENC}=="f91b8373-6349-4de3-86e1-6a2557f2c3f7", RUN+="/home/steve/backup/backup.sh &"
但是我不检查这个方法
来自 http://lists.freedesktop.org/archives/systemd-devel/2012-November/007390.html:
It's completely wrong to launch any long running task from a udev rule
and you should expect that it will be killed. If you need to launch a
process from a udev rule, use ENV{SYSTEMD_WANTS} to activate a
service.
问题:我有一个简单的自定义备份脚本,只要检测到我的备份驱动器,它就会设置为 运行,这是通过 udev 完成的。一切都很好,直到脚本执行到一半时它似乎在 rsync 命令之后挂起。我的代码如下:
#!/bin/bash
#Mount the Backup Drive
wall "backup is starting"
mount -U f91b8373-6349-4de3-86e1-6a2557f2c3f7 /media/backupdrive
#Get updated package-list
mv /media/backupdrive/package-selections /media/backupdrive/package-selections.old
dpkg --get-selections >/media/backupdrive/package-selections
wall "pacakge list updated"
#Run Backup
mv /home/user/backup/rsync.log /home/user/backup/rsync.log.old
rsync --log-file=/media/backupdrive/backup/rsync.log -ravzX --delete --exclude /var/tmp --exclude /var/lock --exclude /var/run /home /etc /var /usr /media/backupdrive/backup
wall "rsync complete"
#Sync changes to disk and unmount
sync
cp /media/backupdrive/backup/rsync.log /home/user/backup/rsync.log
umount /media/backupdrive
wall "Backup is complete, the logfile can be viewed at /home/user/backup/rsync.log"
问题:我哪里做错了,为什么脚本在 rsync 后没有继续?
PS - 墙命令对脚本来说并不重要,我将它们放在不同的位置进行故障排除,是的,我是新手:)
编辑 - 我曾尝试删除类似问题中提到的 "z" 选项,但这没有任何区别
这就像udev中的运行命令超时。 不是直接从 udev 运行ning 备份脚本(通常需要很长时间才能完成),您可以 运行 它来自单独的进程,由 udev 激活。
例如你可以使用at
命令:
ACTION=="add", KERNEL=="sd*", ENV{ID_FS_UUID_ENC}=="f91b8373-6349-4de3-86e1-6a2557f2c3f7", RUN+="/home/steve/backup/backup_at.sh"
backup_at.sh:
#!/bin/sh
echo /home/steve/backup/backup.sh | at now
或者你可以尝试在后台运行它:
ACTION=="add", KERNEL=="sd*", ENV{ID_FS_UUID_ENC}=="f91b8373-6349-4de3-86e1-6a2557f2c3f7", RUN+="/home/steve/backup/backup.sh &"
但是我不检查这个方法
来自 http://lists.freedesktop.org/archives/systemd-devel/2012-November/007390.html:
It's completely wrong to launch any long running task from a udev rule and you should expect that it will be killed. If you need to launch a process from a udev rule, use ENV{SYSTEMD_WANTS} to activate a service.