smilerryan

[LUA] ComputerCraft Backup/Recovery Tool

Sep 23rd, 2018
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.75 KB | None | 0 0
  1. -- SmilerRyan's Backup And Recovery Tool:
  2. -- Moves files to disk so they can be recovered later.
  3. -- NOTE: Recovery will OVERWRITE all files on the machine.
  4. -- USAGE: Insert floppy with disk in device(s) to copy from/to.
  5. -- DOWNLOAD (ON EMPTY FLOPPY): pastebin get cbTdp8B0 /disk/startup
  6.  
  7. shell.run("clear")
  8. local DT = "unknown"
  9. term.setCursorPos(2,2)
  10. if fs.isDir("/disk/r") then DT = "recovery" else DT = "backup" end
  11. if term.isColor() then term.setTextColor(colors.yellow) end
  12. print("Backup/Recovery Tool by SmilerRyan\n")
  13. print(" This disk will " .. DT .. " your files.")
  14. print(" Warning: Every file/directory will be moved.\n")
  15. print(" To cancel the process, press T.")
  16. print(" Press any key to start...")
  17.  
  18. local ignore={["disk"]=true,["rom"]=true}
  19. local event, key = os.pullEvent( "key" )
  20. local l = "[Backup Disk] "
  21. print("")
  22.  
  23. if key == keys.t then
  24.     term.clear()
  25.     term.setCursorPos(2,2)
  26.     if term.isColor() then  term.setTextColor(colors.red)  end
  27.     write("Backup/Recovery Tool by SmilerRyan\n The " .. DT .. " task was cancelled.\n The drive was not ejected.\n\n")
  28.     if term.isColor() then term.setTextColor(colors.white) end
  29.     return
  30. end
  31.  
  32. print(" " .. DT .. " started")
  33. if fs.isDir("/disk/r") then
  34. for _, filename in ipairs(fs.list("/disk/r")) do if not ignore[filename] then fs.move("/disk/r/"..filename, "/"..filename) end end
  35. fs.delete("/disk/r")
  36. l = l .. "empty"
  37. else
  38. fs.makeDir("/disk/r");
  39. for _, filename in ipairs(fs.list("")) do if not ignore[filename] then fs.move(filename, "/disk/r/"..filename) end end
  40. l = l .."full"
  41. end
  42.  
  43. local sides = {"top","bottom","left","right","front","back"}
  44. for i, side in pairs(sides) do
  45.     disk.setLabel(side, l)
  46.     disk.eject(side)
  47. end
  48.  
  49. sleep(2)
  50. write(" " .. DT .. " complete!\nRebooting...")
  51. os.reboot()
Add Comment
Please, Sign In to add comment