restore_backups.lua
74 lines ยท 1.7 KB
eHydra Backup Restoration System
Copy & run
wget https://perlytiara.github.io/turtles.tips/raw/programs/perlytiara/eHydra_wip/restore_backups.lua
| 1 | -- eHydra Backup Restoration System |
| 2 | -- Restores eHydra programs from backup files |
| 3 | |
| 4 | local eHydraPrograms = { |
| 5 | "autoupdater.lua", |
| 6 | "batch_updater.lua", |
| 7 | "init.lua", |
| 8 | "turtle_deployer.lua", |
| 9 | "startup.lua", |
| 10 | "self_update.lua", |
| 11 | "README.md" |
| 12 | } |
| 13 | |
| 14 | print("eHydra Backup Restoration v1.0") |
| 15 | print("==============================") |
| 16 | |
| 17 | -- Check for available backups |
| 18 | local backupsFound = {} |
| 19 | for _, filename in ipairs(eHydraPrograms) do |
| 20 | local backupPath = filename .. ".backup" |
| 21 | if fs.exists(backupPath) then |
| 22 | table.insert(backupsFound, filename) |
| 23 | end |
| 24 | end |
| 25 | |
| 26 | if #backupsFound == 0 then |
| 27 | print("โ No backup files found.") |
| 28 | print("Backups are only created during updates.") |
| 29 | return |
| 30 | end |
| 31 | |
| 32 | print("๐ฆ Found " .. #backupsFound .. " backup file(s):") |
| 33 | for i, filename in ipairs(backupsFound) do |
| 34 | print(" " .. i .. ". " .. filename) |
| 35 | end |
| 36 | |
| 37 | print() |
| 38 | write("Restore all backups? (y/n) [n]: ") |
| 39 | local confirm = string.lower(read()) |
| 40 | |
| 41 | if confirm ~= "y" then |
| 42 | print("Restoration cancelled.") |
| 43 | return |
| 44 | end |
| 45 | |
| 46 | print() |
| 47 | print("๐ Restoring backup files...") |
| 48 | |
| 49 | local restored = 0 |
| 50 | for _, filename in ipairs(backupsFound) do |
| 51 | local backupPath = filename .. ".backup" |
| 52 | |
| 53 | print("Restoring " .. filename .. "...") |
| 54 | |
| 55 | -- Delete current file if it exists |
| 56 | if fs.exists(filename) then |
| 57 | fs.delete(filename) |
| 58 | end |
| 59 | |
| 60 | -- Restore from backup |
| 61 | fs.copy(backupPath, filename) |
| 62 | fs.delete(backupPath) |
| 63 | |
| 64 | print(" โ " .. filename .. " restored") |
| 65 | restored = restored + 1 |
| 66 | end |
| 67 | |
| 68 | print() |
| 69 | print("๐ Restoration complete!") |
| 70 | print("โ Restored " .. restored .. " files") |
| 71 | print("๐๏ธ Backup files have been removed") |
| 72 | print() |
| 73 | print("eHydra has been restored to previous versions.") |
| 74 |