1. bare naked backup

Psssst... Hey, you! Do you like to live dangerously? Interested in something quick and dirty?

-- 
--  backup.e 
-- 
 
include std/filesys.e 
 
public function backup( sequence file, integer w = 1) 
--  default is destructive file copy 
sequence backup_file = file & "~" 
if w = 0 then 
    while file_exists(backup_file) do 
        backup_file &= "~" 
    end while 
end if 
return copy_file(file, backup_file, w) 
end function 
 
public function restore( sequence backup_file , integer overwrite = 1) 
return copy_file(backup_file, backup_file[1..match("~", backup_file)-1], 1) 
end function 
 
public function purge_backup_file( sequence backup_file ) 
return delete_file( backup_file ) 
end function 
-- 
-- backup.ex 
-- 
-- usage: eui backup.ex <file_name> 
-- 
 
include backup.e 
 
integer w = 1 -- set to 0 for safe backup 
 
object cl = command_line() 
if length(cl) = 3 then 
    backup(cl[3], w) 
end if 
-- 
-- restore.ex 
-- 
-- usage: eui restore.ex <backup_file> 
-- 
 
include backup.e 
 
object cl = command_line() 
if length(cl) = 3 then 
    if match("~", cl[3]) then 
        restore(cl[3]) 
    end if 
end if 
-- 
--  purge_backup_file.ex 
-- 
--  usage: eui purge_backup_file.ex <backup_file> 
-- 
include backup.e 
 
object cl = command_line() 
if length(cl) = 3 then 
    if match("~", cl[3]) then 
        purge_backup_file(cl[3]) 
    end if 
end if 
 

Comments and suggestions for improvements will be appreciated.

new topic     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu