Class: DatedBackup
- Inherits:
-
Object
- Object
- DatedBackup
- Includes:
- CommandLine
- Defined in:
- lib/dated_backup/command_line.rb,
lib/dated_backup/dated_backup.rb
Defined Under Namespace
Modules: CommandLine
Instance Attribute Summary collapse
-
#backup_root ⇒ Object
Returns the value of attribute backup_root.
-
#destination ⇒ Object
Returns the value of attribute destination.
-
#opts ⇒ Object
Returns the value of attribute opts.
-
#source ⇒ Object
Returns the value of attribute source.
-
#user_domain ⇒ Object
Returns the value of attribute user_domain.
Instance Method Summary collapse
- #cp_last_backup_to_new_backup ⇒ Object
- #create_backup ⇒ Object
- #create_main_backup_directory ⇒ Object
-
#initialize(h = {}) ⇒ DatedBackup
constructor
A new instance of DatedBackup.
-
#run ⇒ Object
create the first backup, if non-existent otherwise cp -al (or # replace cp -al a b with cd a && find . -print | cpio -dpl ../b ) and then create the backup of the dirs using rsync -a –delete the files, in the end, should be read only and undeletable.
Methods included from CommandLine
Constructor Details
#initialize(h = {}) ⇒ DatedBackup
Returns a new instance of DatedBackup.
9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/dated_backup/dated_backup.rb', line 9 def initialize(h={}) @backup_root = h[:destination] @opts = h[:options] || "" @user_domain = h[:user_domain] @destination = generate_backup_filename @sources = h[:sources] || [h[:source]] if @user_domain @sources.map! { |src| "#{@user_domain}:#{src}" } end end |
Instance Attribute Details
#backup_root ⇒ Object
Returns the value of attribute backup_root.
7 8 9 |
# File 'lib/dated_backup/dated_backup.rb', line 7 def backup_root @backup_root end |
#destination ⇒ Object
Returns the value of attribute destination.
7 8 9 |
# File 'lib/dated_backup/dated_backup.rb', line 7 def destination @destination end |
#opts ⇒ Object
Returns the value of attribute opts.
7 8 9 |
# File 'lib/dated_backup/dated_backup.rb', line 7 def opts @opts end |
#source ⇒ Object
Returns the value of attribute source.
7 8 9 |
# File 'lib/dated_backup/dated_backup.rb', line 7 def source @source end |
#user_domain ⇒ Object
Returns the value of attribute user_domain.
7 8 9 |
# File 'lib/dated_backup/dated_backup.rb', line 7 def user_domain @user_domain end |
Instance Method Details
#cp_last_backup_to_new_backup ⇒ Object
42 43 44 45 46 47 |
# File 'lib/dated_backup/dated_backup.rb', line 42 def cp_last_backup_to_new_backup last_backup_dir = find_last_backup_filename cmd = "cp -al #{last_backup_dir} #{@destination}" execute(cmd) end |
#create_backup ⇒ Object
34 35 36 37 38 39 40 |
# File 'lib/dated_backup/dated_backup.rb', line 34 def create_backup @sources.each do |source| cmd = "rsync -a --delete #{opts} #{source} #{@destination}" execute(cmd) puts "\n\n" end end |
#create_main_backup_directory ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/dated_backup/dated_backup.rb', line 49 def create_main_backup_directory begin unless File.exists? backup_root puts "* Creating main backup directory #{backup_root}" Dir.mkdir backup_root end rescue Errno::EACCES => e puts "-- Exiting script because main directory could not be created. \n Error Message: #{e}" exit end end |
#run ⇒ Object
create the first backup, if non-existent
otherwise cp -al (or # replace cp -al a b with cd a && find . -print | cpio -dpl ../b ) and then create the backup of the dirs using rsync -a –delete the files, in the end, should be read only and undeletable
27 28 29 30 31 32 |
# File 'lib/dated_backup/dated_backup.rb', line 27 def run create_main_backup_directory cp_last_backup_to_new_backup unless Dir.glob("#{@backup_root}/*").empty? create_backup #set_permissions(dest) end |