rsync 的“只读文件系统 (30)”错误

rsync 的“只读文件系统 (30)”错误

注意:这是一个由两部分组成的问题:为什么会发生错误,以及如何解决该错误。 (这两部分是相关的,因为“为什么”问题的答案可能会揭示“如何”问题。)


我正在尝试的命令rsync -avuz /some/source/directory .给出了几个(大致)形式的错误

rsync: symlink "/target/directory/foo/bar/baz" -> "../../bar/baz" failed: Read only file system (30)

.../target/directory当前目录在哪里。

我对这个错误感到困惑。确实,该rsync进程没有写入 的权限../..,但我不明白为什么它首先需要这样做:它肯定有写入 的权限/target/directory/foo/bar/baz

尽管如此,在当前的情况下,存在此问题的文件数量仅占正在复制的文件总数的一小部分,因此如果将这些有问题的符号链接“复制到”常规文件就可以了谁的名字已以某种方式改变以表明其特殊性质,以及其内容仅包含原始符号链接的目标。例如,符号链接

/some/source/directory/foo/bar/baz -> ../../bar/baz

之前显示的内容将被“复制到”常规文件

/target/directory/foo/bar/baz-PSEUDOSYMLINK

...由如下所示的一行组成

../../bar/baz

我在将 Unix 目录树复制到 Windows 系统时看到过类似的操作。

有没有一种简单的方法可以做到这一点?

答案1

问题

我用来通过rsync备份我的音乐收藏 ( /mnt/Music/)crontab到较旧的(因此有时容易出错)硬盘 ( /mnt/Music_Backups)。

手动检查该备份分区后,我注意到这些备份有时会(如果通过运行则静默crontab)失败,手动备份尝试也会失败:

sudo rsync -aq --delete /mnt/Music/ /mnt/Music_Backups

    rsync: [generator] failed to set times on \
    "/mnt/Music_Backups/ROCK & POP": Read-only file system (30)

评估

这是我的系统详细信息。

  • 操作系统:Arch Linux x_86。
  • rsync 版本v3.2.3
  • /etc/crontab入口:
# /etc/crontab entry
0 5 * * * root nice -n 19 rsync -aq --delete /mnt/Music/ /mnt/Music_Backups

验证设备、分区、挂载点:

lsblk | grep -B1 -i music_back

    sdd      8:48   1   1.8T  0 disk 
    └─sdd1   8:49   1   1.8T  0 part /mnt/Music_Backups

blkid | grep sdd1

    /dev/sdd1: LABEL="Music_Backups" \
    UUID="b90047d3-147c-491c-a17d-17763f79a12a" \
    BLOCK_SIZE="4096" TYPE="ext4" \
    PARTLABEL="Music_Backups" \
    PARTUUID="98425256-c626-41f1-a85e-6f5feaf412d6"

原因

虽然目标驱动器权限正常:rsync执行以下操作后我遇到了相同的错误:

sudo chown -R root:victoria /mnt/Music_Backups/

...并且分区在磁盘分区实用程序 ( Gparted) 中看起来很好,命令行fsck实用程序表明实际上存在错误:

sudo umount /mnt/Music_Backups/

## Note: if any programs, e.g. a file manager, are using / viewing
## that partition you won't be able to `umount` it until you navigate
## away from anything accessing `/mnt/Music_Backups/`

## Update/CAUTION: do not run fsck on a Network Attached Storage (NAS) 
## hard drive (commonly sold on AMZN ...); these require special 
## software; fsck will kill your HDD.

sudo fsck /dev/sdd1

    fsck from util-linux 2.36
    e2fsck 1.45.6 (20-Mar-2020)
    Music_Backups: recovering journal
    Music_Backups contains a file system with errors, check forced.
    Pass 1: Checking inodes, blocks, and sizes
    Inode 85460709 extent tree (at level 1) could be shorter.  Optimize<y>? yes
    Pass 1E: Optimizing extent trees
    Pass 2: Checking directory structure
    Pass 3: Checking directory connectivity
    Pass 4: Checking reference counts
    Pass 5: Checking group summary information

    Music_Backups: ***** FILE SYSTEM WAS MODIFIED *****
    Music_Backups: 164762/122101760 files (19.8% non-contiguous), 423271337/488378368 blocks

## Recheck:

sudo fsck /dev/sdd1

    fsck from util-linux 2.36
    e2fsck 1.45.6 (20-Mar-2020)
    Music_Backups: clean, 164762/122101760 files, 423271337/488378368 blocks

sudo mount /dev/sdd1 /mnt/Music_Backups/

sudo rsync -aq --delete /mnt/Music/ /mnt/Music_Backups

$ ## completed normally

结论

基于此,我相信当我的操作系统检测到分区上的错误时,它会阻止该分区上的读写,直到这些错误得到解决,从而阻止rsync完成其任务。


笔记

rsync:

  • -a[存档] :相当于-rlptgoD.这是表达您想要递归并想要保留几乎所有内容的快捷方式... [请参阅 https://linux.die.net/man/1/rsync]

  • -q[quiet] :抑制非错误消息


附录 1:失败通知

如前所述,etc/crontab计划备份默默 失败的。这是该问题的解决方案(添加到/etc/crontab)。

DBUS_SESSION_BUS_ADDRESS="unix:path=/run/user/1000/bus"

# add this as one line (broken here, for readability;
# substitute your user name for "victoria"):

0  5  *  *  *  victoria  nice -n 19
  rsync -aq --delete /mnt/Music/ /mnt/Music_Backups ; EXIT_STATUS=$?;
  if [ $EXIT_STATUS -ne 0 ]; then
  notify-send -i warning -t 0 "/etc/crontab for rsync'd Music Backups failed"
  --icon=dialog-information ;
  mutt -s "/etc/crontab for rsync'd Music Backups failed" <your_email_address>; fi

这样,如果备份失败,我将来应该通过屏幕通知和电子邮件收到通知。


notify-send请注意,使用andmutt时存在一些问题/etc/crontab

  • 当以普通用户身份运行时root(例如我:“victoria”),您将看不到通知;并且,您需要muttroot(用户)配置电子邮件帐户。

  • crontab因此,作为普通用户运行该条目要容易得多。我递归地chown将我的备份位置设置为root:victoria,因此将该crontab条目运行为“victoria”不是问题。

  • 如上所述,执行notify-sendvia/etc/crontab需要靠近 顶部的这一行/etc/crontab

DBUS_SESSION_BUS_ADDRESS="unix:path=/run/user/1000/bus"

echo $UID在终端中以普通用户 [例如“victora”(我)] 的身份执行以获得该数字(“1000”,上面)。

详细信息请参见:

尽管如此,我的crontab条目(上面)每天早上 5 点运行,如果备份因任何原因失败,它会(在屏幕上;电子邮件)通知我。

您可以使用此条crontab目测试这些命令(每分钟运行一次;“apples”不是程序,因此肯定会失败):

*  *  *  *  *  <your_user_name>  nice -n 19
  apples -aq --delete /mnt/Music/ /mnt/Music_Backups ; EXIT_STATUS=$?;
  if [ $EXIT_STATUS -ne 0 ]; then
  notify-send -i warning -t 0 "/etc/crontab for rsync'd Music Backups failed"
  --icon=dialog-information ;
  mutt -s "/etc/crontab for rsync'd Music Backups failed" <your_email_address>; fi

附录 2:失败通知

rsync 备份失败的 mutt 电子邮件通知(在 Claws Mail 中查看)

[victoria@victoria ~]$ date
  Wed Jan  6 08:48:38 AM PST 2021

[victoria@victoria ~]$ lsblk

  NAME   MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
  ...
  sdd      8:48   1   1.8T  0 disk 
  └─sdd1   8:49   1   1.8T  0 part /mnt/Music_Backups
  ...

[victoria@victoria ~]$ sudo umount /mnt/Music_Backups/

## Update/CAUTION: do not run fsck on a Network Attached Storage (NAS) 
## hard drive (commonly sold on AMZN ...); these require special 
## software; fsck will kill your HDD.

## Repair disk partition [accept default Y/n suggestions, if present]:

[victoria@victoria ~]$ sudo fsck /dev/sdd1
  fsck from util-linux 2.36.1
  e2fsck 1.45.6 (20-Mar-2020)
  Music_Backups: recovering journal
  Music_Backups contains a file system with errors, check forced.
  Pass 1: Checking inodes, blocks, and sizes
  Pass 2: Checking directory structure
  Pass 3: Checking directory connectivity
  Pass 4: Checking reference counts
  Pass 5: Checking group summary information
  Music_Backups: 165909/122101760 files (20.0% non-contiguous), 425759721/488378368 blocks

## Repeat until no errors:

[victoria@victoria ~]$ sudo fsck /dev/sdd1
  fsck from util-linux 2.36.1
  e2fsck 1.45.6 (20-Mar-2020)
  Music_Backups: clean, 165909/122101760 files, 425759721/488378368 blocks

[victoria@victoria ~]$ sudo mount /dev/sdd1 /mnt/Music_Backups/

## /etc/crontab entry (broken over lines here for readability):

  0    5    *    *    *    victoria    nice -n 19
  rsync -aq --delete /mnt/Music/ /mnt/Music_Backups ; STATUS=$? ;
  if [ $STATUS -ne 0 ]; then notify-send -i warning -t 0 "/etc/crontab
  for rsync'd Music Backups failed" --icon=dialog-information ;
  mutt -s "/etc/crontab for rsync'd Music Backups failed" [email protected] ;
  fi

## Check: manually run Music_Backup command

[victoria@victoria ~]$ time rsync -aq --delete /mnt/Music/ /mnt/Music_Backups
  0:39.91

[victoria@victoria ~]$ 

相关内容