xXm0dzXx

Globalaticla

May 19th, 2012
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.63 KB | None | 0 0
  1. local selection = 2
  2. --<Test ID: nnzXLrVj>--
  3. shell.run("clear")
  4. print("SystemBackup v1.0")
  5. print("\n1; Backup\n2; Restore\n3; Exit")
  6. while true do
  7. local e, k = os.pullEvent( "key" )
  8. if k == 2 or k == 3 then
  9. selection = k
  10. break
  11. elseif k == 4 then
  12. os.reboot()
  13. end
  14. end
  15. if selection == 2 then
  16. backup = fs.open(".backupsaving123", "w")
  17.  
  18. files = fs.list("/")
  19. for i = 1,#files do
  20. if not fs.isReadOnly(files[i]) then
  21. if fs.isDir(files[i]) then
  22. backup.writeLine('fs.makeDir("' ..files[i].. '")')
  23. else
  24. -- Read in the file
  25. local sName = fs.getName( files[i] )
  26. if sName == ".backupsaving123" then else
  27. local file = fs.open( files[i], "r" )
  28. local sText = file.readAll()
  29. file.close()
  30.  
  31. -- POST the contents to pastebin
  32. write( "Backing up " ..sName.. "..." )
  33. local key = "0ec2eb25b6166c0c27a394ae118ad829"
  34. local response = http.post(
  35. "http://pastebin.com/api/api_post.php",
  36. "api_option=paste&"..
  37. "api_dev_key="..key.."&"..
  38. "api_paste_format=lua&"..
  39. "api_paste_name="..textutils.urlEncode(sName).."&"..
  40. "api_paste_code="..textutils.urlEncode(sText)
  41. )
  42.  
  43. if response then
  44. local sResponse = response.readAll()
  45. response.close()
  46.  
  47. local sCode = string.match( sResponse, "[^/]+$" )
  48. backup.writeLine( 'shell.run("pastebin", "get", "'..sCode..'", "'..files[i]..'")')
  49. end
  50. end
  51. end
  52. end
  53. end
  54.  
  55. backup.close()
  56.  
  57.  
  58. -- Read in the file
  59. local sName = fs.getName( ".backupsaving123" )
  60. local file = fs.open( ".backupsaving123" , "r" )
  61. local sText = file.readAll()
  62. file.close()
  63.  
  64. -- POST the contents to pastebin
  65. write( "Connecting to pastebin.com... " )
  66. local key = "0ec2eb25b6166c0c27a394ae118ad829"
  67. local response = http.post(
  68. "http://pastebin.com/api/api_post.php",
  69. "api_option=paste&"..
  70. "api_dev_key="..key.."&"..
  71. "api_paste_format=lua&"..
  72. "api_paste_name="..textutils.urlEncode(sName).."&"..
  73. "api_paste_code="..textutils.urlEncode(sText)
  74. )
  75.  
  76. if response then
  77. local sResponse = response.readAll()
  78. response.close()
  79.  
  80. local sCode = string.match( sResponse, "[^/]+$" )
  81.  
  82. print("Backup Complete! Backup ID: " ..sCode)
  83. else
  84. print("Failed.")
  85. end
  86.  
  87. fs.delete(".backupsaving123")
  88. else
  89. write("\nBackup ID: ")
  90. id = read()
  91. shell.run("pastebin", "get", id, "backupretreiver")
  92. shell.run("backupretreiver")
  93. fs.delete("backupretreiver")
  94. print("Complete!")
  95. end
Advertisement
Add Comment
Please, Sign In to add comment