-
Notifications
You must be signed in to change notification settings - Fork 0
Archives
Archives support:
- Files
- Directories
The following examples should be placed in your Backup configuration file.
Backup::Model.new(:my_backup, 'My Backup') do
# examples go here...
end
The following creates a single .tar
file called my_archive.tar
archive :my_archive do |archive|
# add a file
archive.add '/path/to/a/file.rb'
# add a folder (including sub-folders)
archive.add '/path/to/a/folder/'
# exclude a file
archive.exclude '/path/to/a/excluded_file.rb'
# exclude a folder (including sub-folders)
archive.exclude '/path/to/a/excluded_folder/'
end
- You can archive as many files and folders as you like within the
archive
block - You can have as many
archive
blocks as you like within your configuration file
The archive above would be saved as archives/my_archive.tar
. If a Compressor has been added to the
backup, then the output of the tar command will be piped through the selected compressor. So, if Gzip is the
compressor, the output would be archives/my_archive.tar.gz
.
When using archive.add
to add files or folders, if the given path does not exist,
a warning will be logged and the path will be omitted from the generated tar
command.
This is to prevent a backup from failing should a file or folder not exist.
If you need to backup files or folder that may not exist at the time the backup is run, you should check for their existance before adding them to avoid the warnings, like so:
archive :my_archive do |archive|
# add files
['path/to/file.rb',
'path/to/file.txt'
].each {|file| archive.add(file) if File.exist?(file) }
# add folders (including sub-folders)
['/path/to/folder_a', 'path/to/folder_b'].each do |folder|
archive.add(folder) if File.exist?(folder)
end
end
Archives also have a tar_options
method, which can be used to add additional options to the tar
command used to
create the archive.
For example, to have tar
follow symlinks and store extended attributes, you could use:
archive :my_archive do |archive|
archive.add '/path/to/a/file.rb'
archive.tar_options '-h --xattrs'
end
The options available for tar
will depend on your system. See tar --help
or man tar
for details.
Note: Do not add compression flags using tar_options
. To compress your archives, add a Compressor.