This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
ComputerCraftFan11's profile picture

[1.31+] [HTTP] SystemBackup v1.0

Started by ComputerCraftFan11, 08 May 2012 - 02:01 AM
ComputerCraftFan11 #1
Posted 08 May 2012 - 04:01 AM
Have you ever wanted to backup yours hard drive and send it to another PC on a different server? Well that's what this program was made for!

Open the program and get 2 options:

1; Backup
SpoilerWhen you press backup, the program will create a new temporary file. It will then scan your PC.

If it detects a folder then it will write this code into the new file:

fs.makeDir(*foldername*)
If it detects a file, it will first upload that file to pastebin. After that, it will take the pastebin ID of that file and do this:

shell.run("pastebin", "get", "*file id*", "*file name*")

At the very end, it uploads the temporary file with all the files inside of it to pastebin. The ID of that file is your backup ID.
2; Restore
SpoilerAfter the long process of backing up your PC, it should give you a backup ID. That ID is actually using pastebin. When you enter that code, the program gets the file ID from pastebin and executes it. The reason it can be executed is because the backup stores all the files in lua. So after it being ran, it creates all the files/folders and deletes the file that has the program's data.

THIS REQUIRES THE HTTP API TO BE ENABLED!

Download

local selection = 2
--<Test ID: nnzXLrVj>--
shell.run("clear")
print("SystemBackup v1.0")
print("n1; Backupn2; Restoren3; 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&amp;"..
	 "api_dev_key="..key.."&amp;"..
	 "api_paste_format=lua&amp;"..
	 "api_paste_name="..textutils.urlEncode(sName).."&amp;"..
	 "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&amp;"..
	"api_dev_key="..key.."&amp;"..
	"api_paste_format=lua&amp;"..
	"api_paste_name="..textutils.urlEncode(sName).."&amp;"..
	"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

tl;dr

The program uploads all your files to pastebin. Then creates a pastebin that links to all your files on pastebin.
Rwkeith #2
Posted 08 May 2012 - 07:40 PM
I guess it's more convenient. Good contribution.
PoLoMoTo #3
Posted 08 May 2012 - 11:56 PM
So and files on my computer in the folder lua will be available to me on any server?
ComputerCraftFan11 #4
Posted 09 May 2012 - 02:44 AM
So and files on my computer in the folder lua will be available to me on any server?

Yes it will, but you need the backup ID
PoLoMoTo #5
Posted 09 May 2012 - 09:32 PM
So and files on my computer in the folder lua will be available to me on any server?

Yes it will, but you need the backup ID

Even if you're not using this code? I was thinking using the move program to just move the file into my lua folder
ComputerCraftFan11 #6
Posted 10 May 2012 - 12:53 AM
So and files on my computer in the folder lua will be available to me on any server?

Yes it will, but you need the backup ID

Even if you're not using this code? I was thinking using the move program to just move the file into my lua folder

You cant access the lua folder with move
PoLoMoTo #7
Posted 10 May 2012 - 01:07 AM
What can I use to access the lua folder?
ComputerCraftFan11 #8
Posted 10 May 2012 - 02:17 AM
What can I use to access the lua folder?

You can't. That's what this program is for.
PoLoMoTo #9
Posted 11 May 2012 - 10:24 PM
>.< Kk thanks
ComputerCraftFan11 #10
Posted 15 May 2012 - 04:37 AM
Woah, just noticed it doesn't copy the files INSIDE of folders.