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.
Constant Summary collapse
- INVALID_FTP_ARG_MSG =
"Invalid arguments for ftp"
Instance Method Summary collapse
-
#backup ⇒ Object
Starts off the backup script.
-
#destination_file(filename) ⇒ Object
Full path and name of the package file to create.
-
#file(filename = nil) ⇒ Object
(also: #dir)
File or directory name to add to the backup set.
-
#ftp(host, user, passwd, options = {}) ⇒ Object
After packaging backup set send the file to this server.
Instance Method Details
#backup ⇒ Object
Starts off the backup script.
Usage:
backup do
# add your files, dirs etc. here...
end
40 41 42 |
# File 'lib/back_it_up/config.rb', line 40 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
82 83 84 85 |
# File 'lib/back_it_up/config.rb', line 82 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
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/back_it_up/config.rb', line 53 def file(filename = nil) unless (filename == "" || filename == nil) full_name = File.(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 |
#ftp(host, user, passwd, options = {}) ⇒ Object
After packaging backup set send the file to this server.
Options:
<tt>:remote_dir</tt> Remote directory on FTP host
27 28 29 30 31 |
# File 'lib/back_it_up/config.rb', line 27 def ftp(host, user, passwd, = {} ) raise INVALID_FTP_ARG_MSG if host.blank? || user.blank? || passwd.blank? @ftp_options = .merge( {:user => user, :host => host, :passwd => passwd } ) end |