Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local selection = 2
- --<Test ID: nnzXLrVj>--
- shell.run("clear")
- print("SystemBackup v1.0")
- print("\n1; Backup\n2; Restore\n3; Exit")
- while true do
- local e, k = os.pullEvent( "key" )
- if k == 2 or k == 3 then
- selection = k
- break
- elseif k == 4 then
- os.reboot()
- end
- end
- if selection == 2 then
- backup = fs.open(".backupsaving123", "w")
- files = fs.list("/")
- for i = 1,#files do
- if not fs.isReadOnly(files[i]) then
- if fs.isDir(files[i]) then
- backup.writeLine('fs.makeDir("' ..files[i].. '")')
- else
- -- Read in the file
- local sName = fs.getName( files[i] )
- if sName == ".backupsaving123" then else
- local file = fs.open( files[i], "r" )
- local sText = file.readAll()
- file.close()
- -- POST the contents to pastebin
- write( "Backing up " ..sName.. "..." )
- local key = "0ec2eb25b6166c0c27a394ae118ad829"
- local response = http.post(
- "http://pastebin.com/api/api_post.php",
- "api_option=paste&"..
- "api_dev_key="..key.."&"..
- "api_paste_format=lua&"..
- "api_paste_name="..textutils.urlEncode(sName).."&"..
- "api_paste_code="..textutils.urlEncode(sText)
- )
- if response then
- local sResponse = response.readAll()
- response.close()
- local sCode = string.match( sResponse, "[^/]+$" )
- backup.writeLine( 'shell.run("pastebin", "get", "'..sCode..'", "'..files[i]..'")')
- end
- end
- end
- end
- end
- backup.close()
- -- Read in the file
- local sName = fs.getName( ".backupsaving123" )
- local file = fs.open( ".backupsaving123" , "r" )
- local sText = file.readAll()
- file.close()
- -- POST the contents to pastebin
- write( "Connecting to pastebin.com... " )
- local key = "0ec2eb25b6166c0c27a394ae118ad829"
- local response = http.post(
- "http://pastebin.com/api/api_post.php",
- "api_option=paste&"..
- "api_dev_key="..key.."&"..
- "api_paste_format=lua&"..
- "api_paste_name="..textutils.urlEncode(sName).."&"..
- "api_paste_code="..textutils.urlEncode(sText)
- )
- if response then
- local sResponse = response.readAll()
- response.close()
- local sCode = string.match( sResponse, "[^/]+$" )
- print("Backup Complete! Backup ID: " ..sCode)
- else
- print("Failed.")
- end
- fs.delete(".backupsaving123")
- else
- write("\nBackup ID: ")
- id = read()
- shell.run("pastebin", "get", id, "backupretreiver")
- shell.run("backupretreiver")
- fs.delete("backupretreiver")
- print("Complete!")
- end
Advertisement
Add Comment
Please, Sign In to add comment