Pulihkan file yang terhapus secara tidak sengaja pada instans ECS Linux menggunakan testdisk dan penyambungan ulang disk.
Latar Belakang
Alur kerja dan alat dalam topik ini membantu memulihkan file yang terhapus secara tidak sengaja. Hasil pemulihan bervariasi tergantung pada skenario dan metode yang digunakan. Pilih tindakan yang sesuai berdasarkan situasi aktual Anda.
Prasyarat
-
Anda telah membaca bagian Alur Kerja.
-
Anda memiliki pengetahuan dan keterampilan untuk memulihkan data tanpa menyebabkan korupsi lebih lanjut.
-
Anda telah membuat snapshot untuk disk yang datanya ingin dipulihkan guna mencegah korupsi akibat operasi yang salah.
-
Topik ini menggunakan perangkat lunak open source pihak ketiga untuk pemulihan data. Alibaba Cloud tidak menjamin hasil pemulihan dari perangkat lunak pihak ketiga.
-
Jika data tersebut kritis dan Anda tidak memiliki keahlian pemulihan data, hubungi lembaga pemulihan data profesional alih-alih memulihkan data secara manual.
Alur Kerja
Pulihkan data saat sistem tidak dapat dijalankan setelah penghapusan tidak sengaja
Jika Anda menjalankan rm -rf /* sebagai pengguna root pada instans Linux dan CLI grub muncul setelah restart, ikuti alur kerja ini untuk memulihkan data dari disk sistem sumber.
Pulihkan data setelah file sistem terhapus secara tidak sengaja
Jika Anda menjalankan rm -rf <file_or_dir> pada instans Linux dan perlu memulihkan data yang terhapus, ikuti alur kerja ini.
Jika penghapusan menyebabkan kegagalan koneksi SSH, gunakan VNC (VNC) untuk menghubungkan ke instans.
Panduan Operasi
Contoh berikut menunjukkan pemulihan data menggunakan testdisk saat instans tidak dapat dijalankan setelah penghapusan tidak sengaja.
Kasus Penggunaan
-
Anda secara tidak sengaja menjalankan
rm -rf /*dan instans tidak dapat dijalankan. -
Tidak ada snapshot yang dibuat sebelum penghapusan, atau Anda lebih memilih untuk tidak menggunakan snapshot dalam pemulihan.
-
Anda ingin memulihkan data menggunakan instans Linux lain.
Bagan Alir Operasi
Bagan alir berikut menunjukkan prosedur pemulihan data.
Prosedur
-
Buat snapshot untuk instans saat ini.
Sebelum memulihkan data, buat snapshot untuk disk sistem atau disk data instans target sebagai cadangan data yang ada. Lihat Buat snapshot untuk disk.
-
Lepaskan disk dari instans sumber dan sambungkan ke instans lain.
PeringatanSebelum melepas disk sistem, hentikan instans tersebut. Di Konsol ECS, pilih Force Stop. Jika tidak, disk sistem tidak dapat dilepas.
Force Stop setara dengan mematikan daya instans. Data yang belum ditulis ke disk dalam sistem operasi mungkin hilang. Lakukan dengan hati-hati.
Lepaskan disk sistem atau disk data dan sambungkan ke instans Linux normal lainnya. Lihat Lepas atau sambungkan disk sistem.
PeringatanSaat Anda menyambungkan disk sistem sumber ke instans lain sebagai disk data, Konsol ECS mungkin akan meminta Anda untuk menginisialisasi disk tersebut. Jangan pilih Initialize Now. Tutup kotak dialog tersebut dan lanjutkan. Jika tidak, data yang akan dipulihkan akan rusak.
-
Pulihkan data yang terhapus secara tidak sengaja.
Gunakan testdisk untuk memulihkan data atau direktori yang terhapus. Contoh berikut memulihkan direktori yang terhapus pada instans Linux.
-
Instal testdisk pada instans normal. Perintahnya berbeda-beda tergantung sistem operasi.
Alibaba Cloud Linux 2 atau 3
sudo yum install -y testdiskCentOS 6, CentOS 7, atau CentOS 8
sudo yum install -y testdiskUbuntu atau Debian
sudo apt install -y testdisk -
Periksa partisi disk saat ini:
sudo fdisk -luContoh output:
Disk /dev/vda: 145 GiB, 155692564480 bytes, 304087040 sectors Units: sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disklabel type: gpt Disk identifier: F51132A7-67B1-4650-806D-FD0DE6E1210C Device Start End Sectors Size Type /dev/vda1 2048 6143 4096 2M BIOS boot /dev/vda2 6144 415743 409600 200M EFI System /dev/vda3 415744 304087006 303671263 144.8G Linux filesystem Disk /dev/vdb: 40 GiB, 42949672960 bytes, 83886080 sectors Units: sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disklabel type: gpt Disk identifier: F51132A7-67B1-4650-806D-FD0DE6E1210C Device Start End Sectors Size Type /dev/vdb1 2048 6143 4096 2M BIOS boot /dev/vdb2 6144 415743 409600 200M EFI System /dev/vdb3 415744 83886046 83470303 39.8G Linux filesystemDalam contoh ini,
/dev/vdaadalah disk sistem instans normal./dev/vdbadalah disk sistem instans sumber, yang disambungkan sebagai disk data. -
Jalankan
testdiskpada disk target:sudo testdisk /dev/vdbPilih
Proceed(default) dan tekan Enter.TestDisk 7.1, Data Recovery Utility, July 2019 Christophe GRENIER <grenier@cgsecurity.org> https://www.cgsecurity.org TestDisk is free software, and comes with ABSOLUTELY NO WARRANTY. Select a media (use Arrow keys, then press Enter): >Disk /dev/vdb - 42 GB / 40 GiB >[Proceed ] [ Quit ] Note: Disk capacity must be correctly detected for a successful recovery. If a disk listed above has an incorrect size, check HD jumper settings and BIOS detection, and install the latest OS patches and disk drivers. -
Pilih gaya tabel partisi. Default-nya adalah Intel. Jika disk menggunakan GUID Partition Table (
GPT), pilih EFI GPT. Tekan Enter.TestDisk 7.1, Data Recovery Utility, July 2019 Christophe GRENIER <grenier@cgsecurity.org> https://www.cgsecurity.org Disk /dev/vdb - 42 GB / 40 GiB Please select the partition table type, press Enter when done. [Intel ] Intel/PC partition >[EFI GPT] EFI GPT partition map (Mac i386, some x86_64...) [Humax ] Humax partition table [Mac ] Apple partition map (legacy) [None ] Non partitioned media [Sun ] Sun Solaris partition [XBox ] XBox partition [Return ] Return to disk selection Hint: EFI GPT partition table type has been detected.Note: Do NOT select 'None' for media with only a single partitio -
Pilih Analyse dan tekan Enter untuk memindai disk.
TestDisk 7.1, Data Recovery Utility, July 2019 Christophe GRENIER <grenier@cgsecurity.org> https://www.cgsecurity.org Disk /dev/vdb - 42 GB / 40 GiB CHS 83220 16 63 - sector size=512 >[ Analyse ] Analyse current partition structure and search for lost partitions [ Advanced ] Filesystem Utils [ Geometry ] Change disk geometry [ Options ] Modify options [ Quit ] Return to disk selection Note: Correct disk geometry is required for a successful recovery. 'Analyse' process may give some warnings if it thinks the logical geometry is mismatched. -
Jika informasi partisi tidak muncul, pilih Quick Search dan tekan Enter.
TestDisk 7.1, Data Recovery Utility, July 2019 Christophe GRENIER <grenier@cgsecurity.org> https://www.cgsecurity.org Disk /dev/vdb - 42 GB / 40 GiB - CHS 83220 16 63 Current partition structure: Partition Start End Size in sectors 1 P Unknown 2048 6143 4096 2 P EFI System 6144 415743 409600 3 P Linux filesys. data 415744 83886046 83470303 P=Primary D=Deleted >[Quick Search] [ Backup ] Try to locate partitionSaat informasi partisi muncul, pilih partisi target dan tekan Enter.
TestDisk 7.1, Data Recovery Utility, July 2019 Christophe GRENIER <grenier@cgsecurity.org> https://www.cgsecurity.org Disk /dev/vdb - 42 GB / 40 GiB - CHS 83220 16 63 Partition Start End Size in sectors P MS Data 6144 415743 409600 >P Linux filesys. data 415744 83886039 83470296 [root] Structure: Ok. Use Up/Down Arrow keys to select partition. Use Left/Right Arrow keys to CHANGE partition characteristics: P=Primary D=Deleted Keys A: add partition -
Pilih Deeper Search dan tekan Enter.
TestDisk 7.1, Data Recovery Utility, July 2019 Christophe GRENIER <grenier@cgsecurity.org> https://www.cgsecurity.org Disk /dev/vdb - 42 GB / 40 GiB - CHS 83220 16 63 Partition Start End Size in sectors 1 P MS Data 6144 415743 409600 2 P Linux filesys. data 415744 83886039 83470296 [root] [ Quit ] [ Return ] >[Deeper Search] [ Write ] Try to find more partitions -
Saat file yang dapat dipulihkan muncul, pilih Continue dan tekan Enter.
TestDisk 7.1, Data Recovery Utility, July 2019 Christophe GRENIER <grenier@cgsecurity.org> https://www.cgsecurity.org Disk /dev/vdb - 42 GB / 40 GiB - CHS 83220 16 63 The harddisk (42 GB / 40 GiB) seems too small! (< 75 GB / 70 GiB) Check the harddisk size: HD jumper settings, BIOS detection... The following partitions can't be recovered: Partition Start End Size in sectors > Linux filesys. data 677886 84148181 83470296 [root] Linux filesys. data 1202174 84672469 83470296 [root] Linux filesys. data 1726462 85196757 83470296 [root] Linux filesys. data 2250750 85721045 83470296 [root] Linux filesys. data 2775038 86245333 83470296 [root] Linux filesys. data 6969342 90439637 83470296 [root] Linux filesys. data 7493630 90963925 83470296 [root] Linux filesys. data 13260798 96731093 83470296 [root] Linux filesys. data 17461456 100931751 83470296 [root] Linux filesys. data 17461598 100931893 83470296 [root] [ Continue ] ext4 blocksize=4096 Large_file Sparse_SB Recover, 42 GB / 39 GiBTekan P untuk menampilkan daftar file.
TestDisk 7.1, Data Recovery Utility, July 2019 Christophe GRENIER <grenier@cgsecurity.org> https://www.cgsecurity.org P Linux filesys. data 415744 83886039 83470296 [root] Directory / >dr-xr-xr-x 0 0 4096 20-Dec-2024 10:06 . dr-xr-xr-x 0 0 4096 20-Dec-2024 10:06 .. drwxr-xr-x 0 0 4096 20-Dec-2024 10:06 usr dr-xr-xr-x 0 0 4096 20-Dec-2024 10:03 boot drwxr-xr-x 0 0 4096 4-Nov-2024 09:48 dev drwxr-xr-x 0 0 4096 4-Nov-2024 09:48 proc drwxr-xr-x 0 0 4096 4-Nov-2024 09:48 run drwxr-xr-x 0 0 4096 4-Nov-2024 09:48 sys drwxr+xr-x 0 0 0 20-Dec-2024 10:06 etc -rw------- 0 0 0 20-Dec 2024 10:06 root drwxr-xr-x 0 0 4096 20-Dec-2024 10:06 var drwxr-xr-x 0 0 4096 20 Dec-2024 10:06 usr lrwxrwxrwx 0 0 7 9-Feb-2022 20:18 bin lrwxrwxrwx 0 0 8 9-Feb 2022 20:18 sbin lrwxrwxrwx 0 0 7 9-Feb-2022 20:18 lib lrwxrwxrwx 0 0 9 9 Feb 2022 20:18 lib64 lrwxrwxrwx 0 0 7 9-Feb-2022 20:18 bin;672827fb drwxr-xr-x 0 0 8 20-Dec-2024 18:03 home -rw------- 0 0 8 20-Dec-2024 09:43 .ismount-test-file drwxr-xr-x 0 0 0 29-Dec-2024 18:03 media drwxr-xr-x 0 0 8 20-Dec-2024 10:03 mnt drwxr-xr-x 0 0 8 20-Dec-2024 18:03 opt lrwxrwxrwx 0 0 9 9-Feb-2022 20:18 sbin;672827fb drwxr-xr-x 0 0 8 29-Dec-2024 18:04 srv drwxrwxrwt 0 0 4096 20-Dec-2024 10:06 tmp Next Use Right to change directory, h to hide deleted files q to quit, : to select the current file, a to select all files C to copy the selected files, c to copy the current filePulihkan file dan folder tertentu
Pilih file yang akan dipulihkan dan tekan c.
TestDisk 7.1, Data Recovery Utility, July 2019 Christophe GRENIER <grenier@cgsecurity.org> https://www.cgsecurity.org Linux filesys. data 415744 83886039 83470296 [root] Directory / dr-xr-xr-x 0 0 4096 18-Dec-2024 11:14 . dr-xr-xr-x 0 0 4096 18-Dec-2024 11:14 .. drwx------ 0 0 0 18-Dec-2024 11:13 lost+found dr-xr-xr-x 0 0 4096 18-Dec-2024 11:13 boot drwxr-xr-x 0 0 4096 4-Nov-2024 09:48 dev drwxr-xr-x 0 0 4096 4-Nov-2024 09:48 proc drwxr-xr-x 0 0 4096 4-Nov-2024 09:48 run drwxr-xr-x 0 0 4096 4-Nov-2024 09:48 sys drwxr-xr-x 0 0 0 18-Dec-2024 11:15 etc dr-xr-x--- 0 0 4096 18-Dec-2024 11:14 root drwxr-xr-x 0 0 4096 4-Nov-2024 10:03 var drwxr-xr-x 0 0 4096 4-Nov-2024 09:48 usr lrwxrwxrwx 0 0 7 9-Feb-2022 20:18 bin lrwxrwxrwx 0 0 8 9-Feb-2022 20:18 sbin Next Use Right to change directory, h to hide deleted files q to quit, : to select the current file, a to select all files C to copy the selected files, c to copy the current filePulihkan semua file
Tekan a untuk memilih semua file, lalu tekan C untuk menyalin.
TestDisk 7.1, Data Recovery Utility, July 2019 Christophe GRENIER <grenier@cgsecurity.org> https://www.cgsecurity.org P Linux filesys. data 415744 83886039 83470296 [root] Directory / >dr-xr-xr-x 0 0 4096 20-Dec-2024 10:06 . dr-xr-xr-x 0 0 4096 20-Dec-2024 10:06 .. *drwxr-xr-x 0 0 4096 20-Dec-2024 10:06 usr *dr-xr-xr-x 0 0 4096 20-Dec-2024 10:03 boot *drwxr-xr-x 0 0 4096 4-Nov-2024 09:48 dev *drwxr-xr-x 0 0 4096 4-Nov-2024 09:48 proc *drwxr-xr-x 0 0 4096 4-Nov-2024 09:48 run *drwxr-xr-x 0 0 4096 4-Nov-2024 09:48 sys *drwxr-xr-x 0 0 0 20-Dec-2024 10:06 etc *-rw------- 0 0 0 20-Dec-2024 10:06 root *drwxr-xr-x 0 0 4096 20-Dec-2024 10:06 var *drwxr-xr-x 0 0 4096 20-Dec-2024 10:06 usr *lrwxrwxrwx 0 0 7 9-Feb-2022 20:18 bin *lrwxrwxrwx 0 0 8 9-Feb-2022 20:18 sbin *lrwxrwxrwx 0 0 7 9-Feb-2022 20:18 lib *lrwxrwxrwx 0 0 9 9-Feb-2022 20:18 lib64 *lrwxrwxrwx 0 0 7 9-Feb-2022 20:18 bin;672827fb *drwxr-xr-x 0 0 0 20-Dec-2024 10:03 home *-rw------- 0 0 0 20-Dec-2024 09:43 .ismount-test-file *drwxr-xr-x 0 0 0 20-Dec-2024 10:03 media *drwxr-xr-x 0 0 0 20-Dec-2024 10:03 mnt *drwxr-xr-x 0 0 0 20-Dec-2024 10:03 opt *lrwxrwxrwx 0 0 8 9-Feb-2022 20:18 sbin;672827fb *drwxr-xr-x 0 0 0 20-Dec-2024 10:04 srv *drwxrwxrwt 0 0 4096 20-Dec-2024 10:06 tmp Next Use Right to change directory, h to hide deleted files q to quit, : to select the current file, a to select all files C to copy the selected files, c to copy the current file -
Pilih direktori tujuan dan tekan C untuk menempelkan file. Dalam contoh ini, file dipulihkan ke /home/ecs-user/data_recovery.
TestDisk 7.1, Data Recovery Utility, July 2019 Please select a destination where /root and any files below will be copied. Keys: Arrow keys to select another directory C when the destination is correct Q to quit Directory /home/ecs-user/data_recovery >drwxrwxr-x 1000 1000 4096 18-Dec-2024 18:05 . drwx------ 1000 1000 4096 18-Dec-2024 18:23 ..Pesan seperti
Copy done! 10 ok, 0 failedmengonfirmasi bahwa file telah disalin.TestDisk 7.1, Data Recovery Utility, July 2019 Christophe GRENIER <grenier@cgsecurity.org> https://www.cgsecurity.org Linux filesys. data 415744 83886039 83470296 [Root] Directory /root Copy done! 10 ok, 0 failed dr-xr-xr-x 0 0 4096 18-Dec-2024 11:14 . dr-xr-xr-x 0 0 4096 18-Dec-2024 11:14 .. drwx------ 0 0 0 18-Dec-2024 11:13 lost+found dr-xr-xr-x 0 0 4096 18-Dec-2024 11:13 boot drwxr-xr-x 0 0 4096 4-Nov-2024 09:48 dev drwxr-xr-x 0 0 4096 4-Nov-2024 09:48 proc drwxr-xr-x 0 0 4096 4-Nov-2024 09:48 run drwxr-xr-x 0 0 4096 4-Nov-2024 09:48 sys drwxr-xr-x 0 0 0 18-Dec-2024 11:15 etc dr-xr-x--- 0 0 4096 18-Dec-2024 11:14 root drwxr-xr-x 0 0 4096 4-Nov-2024 10:03 var drwxr-xr-x 0 0 4096 4-Nov-2024 09:48 usr lrwxrwxrwx 0 0 7 9-Feb-2022 20:18 bin lrwxrwxrwx 0 0 8 9-Feb-2022 20:18 sbin Next Use Right to change directory, h to hide deleted files St q to quit, : to select the current file, a to select all files C to copy the selected files, c to copy the current file -
Hubungkan kembali ke instans dan masuk ke /home/ecs-user/data_recovery. Jika file muncul di direktori tersebut, pemulihan berhasil.
[ecs-user@ root]$ pwd /home/ecs-user/data_recovery/root [ecs-user@ root]$ ls -la total 20 drwxr-xr-x 4 root root 4096 Dec 18 11:14 . drwxrwxr-x 3 ecs-user ecs-user 4096 Dec 18 18:26 .. -rw-r--r-- 1 root root 0 Nov 4 10:06 anaconda-ks.cfg -rw-r--r-- 1 root root 0 Dec 18 11:14 .bash_logout -rw-r--r-- 1 root root 0 Dec 18 11:14 .bash_profile -rw-r--r-- 1 root root 0 Dec 18 11:14 .bashrc -rw-r--r-- 1 root root 0 Dec 18 11:14 .cshrc -rw-r--r-- 1 root root 102 Nov 4 10:06 original-ks.cfg drwxr-xr-x 2 root root 4096 Dec 18 11:14 .pip -rw-r--r-- 1 root root 0 Dec 18 11:14 .pydistutils.cfg -rw-r--r-- 1 root root 0 Dec 18 11:15 script -rw-r--r-- 1 root root 0 Dec 18 11:14 sedZsHuoR drwxr-xr-x 2 root root 4096 Dec 18 11:14 .ssh -rw-r--r-- 1 root root 0 Dec 18 11:14 .tcshrc
-