我反复尝试在同一磁盘的两个分区之间复制一个文件夹。两个分区都使用相同的文件系统 ext4。我使用 cp 命令,但有些文件没有完全复制。我想知道如何进行精确复制。
rodrigorodriguez@Geminis005:~$ uname -a
Linux Geminis005 5.4.0-52-generic #57-Ubuntu SMP Thu Oct 15 10:57:00 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux
rodrigorodriguez@Geminis005:~$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 20.04.1 LTS
Release: 20.04
Codename: focal
rodrigorodriguez@Geminis005:~$ cp -i -r /mnt/e04ba234-8b05-4f4b-b879-e1161e4d205e/VirtualBox/VBoxVMs/WXP_SP3_Activ20200808_COA_PH247 /home/rodrigorodriguez/Documentos
rodrigorodriguez@Geminis005:~$ diff -r -q /mnt/e04ba234-8b05-4f4b-b879-e1161e4d205e/VirtualBox/VBoxVMs/WXP_SP3_Activ20200808_COA_PH247 /home/rodrigorodriguez/Documentos/WXP_SP3_Activ20200808_COA_PH247
Los archivos /mnt/e04ba234-8b05-4f4b-b879-e1161e4d205e/VirtualBox/VBoxVMs/WXP_SP3_Activ20200808_COA_PH247/Snapshots/{3d70c7f3-06bc-451d-8611-a12e13e2ad13}.vdi y /home/rodrigorodriguez/Documentos/WXP_SP3_Activ20200808_COA_PH247/Snapshots/{3d70c7f3-06bc-451d-8611-a12e13e2ad13}.vdi son distintos
Los archivos /mnt/e04ba234-8b05-4f4b-b879-e1161e4d205e/VirtualBox/VBoxVMs/WXP_SP3_Activ20200808_COA_PH247/WXP_SP3_Activ20200808_COA_PH247.vdi y /home/rodrigorodriguez/Documentos/WXP_SP3_Activ20200808_COA_PH247/WXP_SP3_Activ20200808_COA_PH247.vdi son distintos
其他文件复制成功。我尝试逐个复制失败的两个文件,但问题仍然存在。这些是大文件:
odrigorodriguez@Geminis005:~$ ls -l /mnt/e04ba234-8b05-4f4b-b879-e1161e4d205e/VirtualBox/VBoxVMs/WXP_SP3_Activ20200808_COA_PH247/Snapshots/{3d70c7f3-06bc-451d-8611-a12e13e2ad13}.vdi
-rw------- 1 rodrigorodriguez rodrigorodriguez 406847488 oct 23 14:27 /mnt/e04ba234-8b05-4f4b-b879-e1161e4d205e/VirtualBox/VBoxVMs/WXP_SP3_Activ20200808_COA_PH247/Snapshots/{3d70c7f3-06bc-451d-8611-a12e13e2ad13}.vdi
rodrigorodriguez@Geminis005:~$ ls -l /mnt/e04ba234-8b05-4f4b-b879-e1161e4d205e/VirtualBox/VBoxVMs/WXP_SP3_Activ20200808_COA_PH247/WXP_SP3_Activ20200808_COA_PH247.vdi
-rw------- 1 rodrigorodriguez rodrigorodriguez 4349493248 sep 16 05:21 /mnt/e04ba234-8b05-4f4b-b879-e1161e4d205e/VirtualBox/VBoxVMs/WXP_SP3_Activ20200808_COA_PH247/WXP_SP3_Activ20200808_COA_PH247.vdi
我也尝试过 rsync,结果相同:
rodrigorodriguez@Geminis005:/mnt/e04ba234-8b05-4f4b-b879-e1161e4d205e/VirtualBox/VBoxVMs$ rsync -a -v --delete WXP_SP3_Activ20200808_COA_PH247 /home/rodrigorodriguez/Imágenes/
sending incremental file list
WXP_SP3_Activ20200808_COA_PH247/
WXP_SP3_Activ20200808_COA_PH247/WXP_SP3_Activ20200808_COA_PH247.vbox
WXP_SP3_Activ20200808_COA_PH247/WXP_SP3_Activ20200808_COA_PH247.vbox-prev
WXP_SP3_Activ20200808_COA_PH247/WXP_SP3_Activ20200808_COA_PH247.vdi
WXP_SP3_Activ20200808_COA_PH247/Logs/
WXP_SP3_Activ20200808_COA_PH247/Logs/VBox.log
WXP_SP3_Activ20200808_COA_PH247/Logs/VBox.log.1
WXP_SP3_Activ20200808_COA_PH247/Logs/VBox.log.2
WXP_SP3_Activ20200808_COA_PH247/Logs/VBox.log.3
WXP_SP3_Activ20200808_COA_PH247/Snapshots/
WXP_SP3_Activ20200808_COA_PH247/Snapshots/{3d70c7f3-06bc-451d-8611-a12e13e2ad13}.vdi
sent 4,758,018,024 bytes received 192 bytes 62,196,316.55 bytes/sec
total size is 4,756,855,903 speedup is 1.00
rodrigorodriguez@Geminis005:/mnt/e04ba234-8b05-4f4b-b879-e1161e4d205e/VirtualBox/VBoxVMs$ diff -r -q WXP_SP3_Activ20200808_COA_PH247 /home/rodrigorodriguez/Imágenes/WXP_SP3_Activ20200808_COA_PH247
Los archivos WXP_SP3_Activ20200808_COA_PH247/Snapshots/{3d70c7f3-06bc-451d-8611-a12e13e2ad13}.vdi y /home/rodrigorodriguez/Imágenes/WXP_SP3_Activ20200808_COA_PH247/Snapshots/{3d70c7f3-06bc-451d-8611-a12e13e2ad13}.vdi son distintos
Los archivos WXP_SP3_Activ20200808_COA_PH247/WXP_SP3_Activ20200808_COA_PH247.vdi y /home/rodrigorodriguez/Imágenes/WXP_SP3_Activ20200808_COA_PH247/WXP_SP3_Activ20200808_COA_PH247.vdi son distintos
感谢@xiota 和 Adriaan 的评论,我了解到必须确保文件未被使用。因此,我在 PC 启动后立即复制了文件。这样这些文件就成功复制了。但是当我复制其他文件时,问题又出现了。我启动了 PC,复制了两个文件:
rodrigorodriguez@Geminis005:~$ ls -l /mnt/f26fa231-3c3c-4bbd-8449-1a46bb90ca7a/VBox/VBoxVMs/W7Pro_32bit_COA_34VDK/Snapshots
total 26209300
-rwxrwxr-x 1 rodrigorodriguez rodrigorodriguez 5872025600 oct 26 19:34 {05c2e7c2-1cac-421e-a0b3-5b31b6d5f68c}.vdi
-rw------- 1 rodrigorodriguez rodrigorodriguez 468713472 oct 27 06:11 {17cb8409-3c46-4f9e-916e-fbb1e4194b02}.vdi
-rwxrwxr-x 1 rodrigorodriguez rodrigorodriguez 16865296384 oct 26 19:34 {3d97d24f-7795-446a-9bd1-76342bfe9be4}.vdi
-rwxrwxr-x 1 rodrigorodriguez rodrigorodriguez 3983540224 oct 27 05:37 {6e6a3122-96c9-4bcb-b2b9-35a9571d2257}.vdi
复制之前,我确认已安装分区中没有打开任何内容,然后复制文件:
rodrigorodriguez@Geminis005:~$ lsof | grep "f26fa231"
rodrigorodriguez@Geminis005:~$ cp -i /mnt/f26fa231-3c3c-4bbd-8449-1a46bb90ca7a/VBox/VBoxVMs/W7Pro_32bit_COA_34VDK/Snapshots/{17cb8409-3c46-4f9e-916e-fbb1e4194b02}.vdi ~/Documentos/VMTemp/{17cb8409-3c46-4f9e-916e-fbb1e4194b02}_2.vdi
rodrigorodriguez@Geminis005:~$ cmp -l /mnt/f26fa231-3c3c-4bbd-8449-1a46bb90ca7a/VBox/VBoxVMs/W7Pro_32bit_COA_34VDK/Snapshots/{17cb8409-3c46-4f9e-916e-fbb1e4194b02}.vdi ~/Documentos/VMTemp/{17cb8409-3c46-4f9e-916e-fbb1e4194b02}_2.vdi
rodrigorodriguez@Geminis005:~$
此文件(500Mb)复制成功,但下一个文件(4Gb)复制失败:
rodrigorodriguez@Geminis005:~$ cp -i /mnt/f26fa231-3c3c-4bbd-8449-1a46bb90ca7a/VBox/VBoxVMs/W7Pro_32bit_COA_34VDK/Snapshots/{6e6a3122-96c9-4bcb-b2b9-35a9571d2257}.vdi ~/Documentos/VMTemp
rodrigorodriguez@Geminis005:~$ cmp -l /mnt/f26fa231-3c3c-4bbd-8449-1a46bb90ca7a/VBox/VBoxVMs/W7Pro_32bit_COA_34VDK/Snapshots/{6e6a3122-96c9-4bcb-b2b9-35a9571d2257}.vdi ~/Documentos/VMTemp/{6e6a3122-96c9-4bcb-b2b9-35a9571d2257}.vdi
73293892 0 20
73293916 277 57
73293932 277 57
**[...] Here is a list with 870 different bytes**
我再次验证没有打开任何内容,并且备份了完整的 lsof 输出:
rodrigorodriguez@Geminis005:~$ lsof | grep "f26fa231"
rodrigorodriguez@Geminis005:~$ lsof > ~/Documentos/lsof.txt
我不清楚还需要考虑哪些其他步骤,或者是否最好使用其他命令。无论如何,我已经测试了复制的虚拟机并且运行良好。在这种情况下,差异似乎无关紧要。但对于一般用途,我认为更好地了解 CP 命令的正确用法对我来说很重要。
在此先感谢您的帮助。