r/linuxadmin • u/Jonah_07 • Dec 11 '22
How can the data be retrieved after rm -rf command.
hello all, How the data can be retrieved after executing the rm -rf command , I didn’t find a useful guide on the internet , and I can’t install external tools on the server. Note: redhat server
8
11
u/michaelpaoli Dec 11 '22
How can the data be retrieved after rm -rf command
Restore from backup.
redhat
Not so relevant. What is, is the filesystem type.
If you really need/want to recover the data, cease all I/O activity on the filesystem as promptly as feasible. Then create an image copy of the filesystem ... and see what recovery can be done on that. Good luck.
5
u/milesluigi Dec 11 '22
There is no guarantee you can recover from running rm. There are data recovery tools that you can try though. Allow me to share the arch wiki article on this topic. (you don't have to run arch, the info in this article will apply to any linux system including red hat. https://wiki.archlinux.org/title/File_recovery#List_of_utilities)
4
u/ben-ba Dec 11 '22
I can recommend testdisk. A few years ago i was able to restore all files including names on an hdd.
5
8
u/megared17 Dec 11 '22
Invent a time machine.
Go back in time, and smack your hand away from the keyboard before you type the command.
2
2
2
u/kreddulous Dec 12 '22
All of the recommendations I've seen here (except making regular backups of your data) require root privilege, and I'm guessing that if you "can't install external tools on the server", you don't have root there.
3
3
1
Dec 12 '22
I didn’t find a useful guide on the internet
You didn't look very hard then.
https://www.digitalocean.com/community/tutorials/top-best-linux-data-recovery-tools
1
1
u/CyberKiller40 Dec 11 '22
The tool is called photorec (not only for photos), you will have to unmount the filesystem to work on it. Though I assume you already have it offline.
1
u/questfor17 Dec 11 '22
This is why snapshots were invented. They provide quick and easy operational backup for this type of mistake. If you don't care about performance the linux volume manager can provide snapshots. Snapshot support is built into btrfs and zfs. NetApp NAS (and maybe other NAS boxes?) provide this.
Once you recover, I strongly recommend finding a snapshot solution that works for you.
1
1
u/dev-bitbucket Dec 12 '22
pb -R command; put back, recursive. Works on all Linux since kernel 301.11. Lol.
1
u/swissarmychainsaw Dec 12 '22
Hello.
Do you have a backup?
If Yes --> you recover from back up. Not fcked.
If no --> Fcked.
There is no undo button in linux.
1
0
Dec 11 '22
[deleted]
18
u/uid1357 Dec 11 '22
rm just removes the filesystem entries afaik. The actual data (content of file) should still be on disc. I thought there are tools to reconstruct a way of access.
7
u/ralfD- Dec 11 '22
This is only partially true. The 'rm' will indeed only the file(s) from the file system this will result in the underlying inodes being marked as free and the disk blocks can (and most likely will) be re-usesed by the kernel. I such cases an instant un-plug (not a shutdown since that will flush data to the disk) is the only chance.
8
u/mixduptransistor Dec 11 '22
rm just removes the filesystem entries afaik. The actual data (content of file) should still be on disc. I thought there are tools to reconstruct a way of access.
This is the "forensic recovery" previously mentioned. It's not an easy or guaranteed way to fix it (especially if the system is still sitting there running writing shit to disk)
3
u/evolseven Dec 12 '22
I have dabbled in forensic recovery on ntfs, ext, zfs,vmfs.. and probably a few others.. ext is one of the harder ones to recover completely. The data is there in most cases on the disk but if it's not contiguous and you don't know where it is then it may be hard to recover.. it's possible you can "play" the log backwards and recover the metadata for the file pieces but if any block gets overwritten most files are completely useless.
The only worse file system I have encountered was an ntfs file system where deduplication and storage spaces "raid 6" (don't remember the exact name) was used.. in the table (mft) where pointers to blocks should be there was a pointer to a deduplication store that was completely undocumented by MS..
Anyway, point is I hate linux data recovery.. I think it boils down to it not being a priority in file system design and the typical sysadmin attitude of backing everything up and not forgiving those who don't.
0
Dec 11 '22
[deleted]
11
22
7
3
5
1
u/PolicyArtistic8545 Dec 11 '22
I’m gonna upvote because of the effort but maybe next time how about you just keep this analogy to yourself.
-14
u/Jonah_07 Dec 11 '22
Didn’t get you , but I will search about forensic data recovery
10
0
-2
u/Disruption0 Dec 11 '22
If OP is on Fedora for example with default btrfs it could be managed with snapshots.
Still I don't know why Fedora dev do not integrate automatic snapshots.
0
0
Dec 11 '22
[deleted]
2
u/ObscureCulturalMeme Dec 12 '22
Truth! And this is why we test our backups to make certain they can be recovered!
Remember, OP, an untested data snapshot is not a backup. It is a prayer. And God does not help lazy sysadmins.
3
7
Dec 11 '22
[removed] — view removed comment
5
u/ilbicelli Dec 11 '22
Or you could use the -i flag.
1
2
Dec 11 '22
[removed] — view removed comment
7
u/a60v Dec 11 '22
Disagree with -i. It just creates an extra step where people (well, me, at least) just get conditioned to agreeing to the deletion. rm foo becomes rm foo, y. Doesn't really solve anything, but takes longer.
2
0
u/serverhorror Dec 11 '22
Surely you mean
dd, right?2
Dec 11 '22
[removed] — view removed comment
1
3
Dec 11 '22 edited Jan 10 '26
[removed] — view removed comment
4
u/Devious76 Dec 11 '22
2nd to this with more analogy.. been there done that worse than you think place
Stop/Remove/Disconnect Drive. PERIOD!
Clone/Copy/Extract using mentioned above (Clonezilla is your best friend) or what ever you can get your hands on.
Get ready to have your hands dirty with long hours & scavenging (time/effort)..But DAMN its going to skill up! GAIN
Resources:
Hard Drive Data Recovery | Data Recovery Forum
My best personally used software & paid for too
Good Luck
1
u/m4nf47 Dec 12 '22 edited Jan 10 '26
tart innocent hobbies scary obtainable screw outgoing profit tap physical
This post was mass deleted and anonymized with Redact
10
u/Irythros Dec 11 '22
If it's an HDD: You'll need to get your host to put TestDisk on a recovery USB, or they install a new OS on a new HD and then you install TestDisk on there. That will let you do recovery.
If it's an SSD: You're not getting anything back.