Well that's not exactly about chef, you're basically asking how to use tar
.
The command to create an archive of a folder would be
tar -zcvf <backup_thing>.tgz <path_to_backup>
In the tar options:
z
pass the resulting tar archive to gzip for compression
c
instruct tar to compress (create the archive)
v
tells tar to be verbose, so you know at which point it is working, it has a performance impact
f <path>
tells tar to output in a file or device
A correct chef resource for this would be as follow:
execute 'Backup #{dir_name}' do
user 'user'
command "tar -zcvf #{dest}/#{dir_name}_bkp_#{timestmp}.tgz #{dir_name}"
live_stream :true # to see the progress during chef run, remove it and v in tar option if you don't care of it.
end
Using an execute resource avoid spawning a bash process to run tar, it is not needed, the shell_out
class used by execute
under the hood handles it already.
Be warned this is not idempotent, each run of chef will redo this backup command, that's maybe not what you're after.
For an update of jenkins (or something else) out of usual maintenance I would do a manual backup, check it is ok, and then run the upgrade (via chef eventually).
I'd recomend taking the tutorial at https://learn.chef.io and reading through the documentation at https://docs.chef.io