Advertisement
Rnery

Recovery Files...

Nov 5th, 2023 (edited)
1,426
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.95 KB | Source Code | 0 0
  1. #!/usr/bin/env bash
  2.  
  3. check_root() {
  4.   [ "$EUID" -ne 0 ] && echo "This script must be run as root (superuser)."; exit 1
  5. }
  6.  
  7. # Check if the 'extundelete' utility is installed
  8. check_extundelete() {
  9.   [ ! $(command -v extundelete > /dev/null) ] && echo "The 'extundelete' utility is not installed. Please install it before proceeding."; exit 1
  10. }
  11.  
  12. # Recover a deleted file
  13. recover_file() {
  14.   local file_to_recover="$1"
  15.   local device="/dev/sdXY"  # Replace with the appropriate device
  16.  
  17.   extundelete --restore-file "$file_to_recover" --device "$device"
  18.   local exit_code=$?
  19.  
  20.   [ $exit_code -eq 0 ] && echo "File successfully recovered: $file_to_recover" ||
  21. echo "File recovery failed. Please verify the file name and device, and ensure the file has not been overwritten."
  22.  
  23. }
  24.  
  25. main() {
  26.   check_root
  27.   check_extundelete
  28.  
  29.   [ $# -ne 1 ] && echo "Usage: $0 <file_to_recover>"; exit 1
  30.  
  31.   file_to_recover="$1"
  32.   recover_file "$file_to_recover"
  33. }
  34.  
  35. main
  36.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement