|
| 1 | +<?xml version="1.0" encoding="iso-8859-1"?> |
| 2 | +<!DOCTYPE muclient> |
| 3 | + |
| 4 | +<muclient> |
| 5 | +<plugin |
| 6 | + name="Automatic_Backup" |
| 7 | + author="Nick Gammon" |
| 8 | + id="bb6a05ed7534b5db1ed40511" |
| 9 | + language="Lua" |
| 10 | + purpose="Backs up the world file to a new name each day" |
| 11 | + date_written="2010-09-08 09:38:17" |
| 12 | + requires="4.40" |
| 13 | + version="1.0" |
| 14 | + > |
| 15 | +<description trim="y"> |
| 16 | +<![CDATA[ |
| 17 | +Install to backup your world file to a file of the same name with the day/month/year added to it. |
| 18 | +]]> |
| 19 | +</description> |
| 20 | + |
| 21 | +</plugin> |
| 22 | + |
| 23 | +<script> |
| 24 | +<![CDATA[ |
| 25 | +
|
| 26 | +function do_backup () |
| 27 | + -- find name of world file |
| 28 | + local world_file_name = GetInfo (54) |
| 29 | + |
| 30 | + -- if found (ie. not just newly created) back it up |
| 31 | + if world_file_name and world_file_name ~= "" then |
| 32 | + -- strip out .MCL (or .mcl), add the date, and put .MCL back |
| 33 | + world_file_with_date = string.gsub (world_file_name, "%.[Mm][Cc][Ll]$", "") .. |
| 34 | + os.date ("-backup-%d-%b-%Y.MCL") |
| 35 | + |
| 36 | + -- save if possible |
| 37 | + if (Save (world_file_with_date, true) == false) then |
| 38 | + ColourNote ("orange","", "World file backed up as " .. world_file_with_date) |
| 39 | + else |
| 40 | + ColourNote ("red", "", "Could not back up world file.") |
| 41 | + end -- if |
| 42 | + |
| 43 | + end -- if world file name known |
| 44 | +
|
| 45 | +end -- do_backup |
| 46 | +
|
| 47 | +-- back when first connecting |
| 48 | +function OnPluginConnect () |
| 49 | + do_backup () |
| 50 | +end -- OnPluginConnect |
| 51 | +
|
| 52 | +-- back up when disconnecting (eg. after improving it) |
| 53 | +function OnPluginDisconnect () |
| 54 | + do_backup () |
| 55 | +end -- OnPluginDisconnect |
| 56 | +
|
| 57 | +]]> |
| 58 | +</script> |
| 59 | + |
| 60 | +</muclient> |
0 commit comments