Samstag, 12. Mai 2007

Backup one file

I found my self often doing something like that:
sudo cp /boot/grub/menu.lst /boot/grub/menu.lst_bu_2007-05-12_13-20
With the following script all we need to do is:
sudo backup-one-file /boot/grub/menu.lst
And the result is a backup created in /boot/grub/menu.lst_bu_2007-05-12_13-21-30
#!/usr/bin/env ruby

require 'fileutils'

if ARGV.empty?
puts "Usage: backup-one-file <file-name>"
exit
end

source = ARGV[0]

unless File.exist?(source)
puts "Error: File #{source} does not exist!"
exit
end

target = source + "_bu_" + Time.now.strftime("%Y-%m-%d_%H-%M-%S")

begin
FileUtils.cp(source, target)
rescue Exception => e
puts "Could not copy to #{target}"
puts e.message
puts "Maybe you need to run as root!"
else
puts "Backup created in: #{target}"
end

Labels: , ,

0 Kommentare:

Kommentar veröffentlichen

Links zu diesem Post:

Link erstellen

<< Startseite