Add option to disable backup compression

Ruby is not my forte (i.e. I don’t write Ruby) - but here was my secondary thoughts when I saw pax wasn’t installed as default in Ubuntu:

metadata_params = "--transform='s,#{Regexp.escape(@meta_filename).shellescape},#{Regexp.escape(File.basename(@meta_filename)).shellescape},g' #{@meta_filename.shellescape}"
dump_params = "--transform='s,#{Regexp.escape(@dump_filename).shellescape},#{Regexp.escape(File.basename(@dump_filename)).shellescape},g' #{@dump_filename.shellescape}"
uploads_params = ""
if @with_uploads
        upload_directory = "uploads/" + @current_db
	upload_full_path = File.join(Rails.root, "public/" + upload_directory)
	uploads_params = "--transform='s,#{Regexp.escape(upload_full_path).shellescape},#{Regexp.escape(File.basename(@upload_directory)).shellescape},g' #{@upload_full_path.shellescape}"
end
shell_cmd = "tar --create --dereference #{metadata_params} #{dump_params} #{uploads_params} --verbose --show-transformed-names"

# execute our command or log it something.
`#{shell_cmd} | gzip -5 > #{tar_filename}.gz`

###Notes

  • Full pathnames are used on purpose to avoid any possible collisions
  • The only other thing I would consider replacing / escaping is the use of “commas” (,) in the regular expression - other wise file or path names with a comma included might be of issue.
  • could probably do with an anchor at the beginning of the regular expressions.
  • --verbose --show-transformed-names is there to help debug the replacements.

Yes it can be done cleaner - but this hopefully get’s it working…
… again I haven’t tried this in dev.

By the way - Ruby’s Regexp.escape seems poor - it should take a 2nd parameter for the delimiter.