views:

18

answers:

2

Does anyone know how to archive a folder and its contained files as a tgz archive using Rails? What I would like todo is archive the contents of the folder and then have another script which extracts the same folder that was archived.

All of the archiving techniques that I've come across are pretty complicated, I was wondering if there is a simple solution to what I am looking for.

A: 

There is the Minitar library. It works with ruby in general and archiving and unarchiving is as simple as Minitar.pack and Minitar.unpack.

Alberto
+1  A: 

If you server is *nix, the simplest solution is to leverage Ruby's OS integration and call GNU tar using backquotes.

To create an archive:

`tar cvzf #{archive_file_name}.tar.gz #{dir_to_be_archived}`

To unpack it:

`tar zxvf #{archive_file_name}.tar.gz`
buru