4

system("tar -czf #{RAILS_ROOT}/tmp/export-result #{RAILS_ROOT}/tmp/export")

When I decompress the resulting file I get

app/c3ec2057-7d3a-40d9-9a9d-d5c3fe3ffd6f/home/tmp/export/and_the_files

I would like to just get:

export_result/and_the_files

How do I change my TAR call to accomplish this?

solution:

system("tar -czf #{RAILS_ROOT}/tmp/export.tgz --directory=#{RAILS_ROOT}/tmp export/")

Nerian
  • 1,277
  • 2
  • 12
  • 22

2 Answers2

3

This is how you do it,

tar cfz target.tgz --directory=TARGET_DIR subdir_list

In your case it would look like,

tar cfz target.tgz --directory=app/c3ec2057-7d3a-40d9-9a9d-d5c3fe3ffd6f/home/tmp export/
nik
  • 55,788
  • 10
  • 98
  • 140
  • So, first I specify where I want to save the result 'target.tgz' then I specify where the contents are and what subdirs should be removed. Correct? – Nerian Feb 19 '11 at 13:28
  • This is an app hosted at Heroku, so the only place where I can write is RAILS_ROOT/tmp/ how do I write it so that target.tgz end up there? – Nerian Feb 19 '11 at 13:31
  • I did it: system("tar -czf #{RAILS_ROOT}/tmp/export.tgz --directory=#{RAILS_ROOT}/tmp export/") – Nerian Feb 19 '11 at 13:43
  • right! Good for you :-) – nik Feb 19 '11 at 18:27
1

Change to #{RAILS_ROOT} before compression and don't specify it in the source files.

Ignacio Vazquez-Abrams
  • 111,361
  • 10
  • 201
  • 247