Module: BackItUp::ScriptDSL

Included in:
Config
Defined in:
lib/back_it_up/config.rb

Overview

The backup script should look something like this

# sample.backitup

backup do 

  file '/home/robin/backup.this.file'   

  dir '~/Desktop/drop-in-me-for-backup'

  destination_file "/tmp/backupfile"
end

This will backup the file /home/robin/backup.this.file and all the files in the ~/Desktop/drop-in-me-for-backup directory and its sub dirs, and place them in /tmp/backupfile_[date]_time.zip.

Instance Method Summary collapse

Instance Method Details

#backupObject

Starts off the backup script.

Usage:

backup do 
  # add your files, dirs etc. here...
end


28
29
30
# File 'lib/back_it_up/config.rb', line 28

def backup
  yield
end

#destination_file(filename) ⇒ Object

Full path and name of the package file to create. A timestamp will be appended to the filename and the extension is determined by the packager used.

# Using the zip packager with a destination file setting:
/var/backup/mybackup 

# ...then the final result might be:
/var/backup/mybackup_200900527_053032.zip


70
71
72
73
# File 'lib/back_it_up/config.rb', line 70

def destination_file(filename) 
  raise "Invalid destination file." if File.directory?(filename)
  @dest_filename = filename
end

#file(filename = nil) ⇒ Object Also known as: dir

File or directory name to add to the backup set. The given file name is expanded before added to the backup set.

It is safer to use single quotes (especially on Windows file systems) as the support for escape sequences is not as great as double-quoted strings.

file '~/importantfile'  # is safer 
file "~/anotherfile"    # ...than this


41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/back_it_up/config.rb', line 41

def file(filename = nil)
  unless (filename  == "" || filename == nil)
    full_name = File.expand_path(filename)
    
    if File.exists?(full_name)
      if File.directory? full_name
        @dirs << full_name
      else
        @files << full_name
      end
          
    else 
      puts "WARNING: File #{filename} could not be found"    
    end
  end
  
end