patternMinor
Zip/tar a folder using chef resource
Viewed 0 times
chefresourcezipfolderusingtar
Problem
Can someone help me how to take backup for a specific folder and also zip/tar those folders. I am using this for taking a backup actually, but I would like a compressed output:
Is there any chef resource to zip/tar a specific folder ?
bash "backup #{dir_name}" do
user 'user'
cwd "#{path}"
code <<-EOH
cp -rp #{dir_name} #{dest}/#{dir_name}_bkp_#{timestmp}
EOH
endIs there any chef resource to zip/tar a specific folder ?
Solution
Well that's not exactly about chef, you're basically asking how to use
The command to create an archive of a folder would be
In the tar options:
A correct chef resource for this would be as follow:
Using an execute resource avoid spawning a bash process to run tar, it is not needed, the
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
tar.The command to create an archive of a folder would be
tar -zcvf .tgz In the tar options:
zpass the resulting tar archive to gzip for compression
cinstruct tar to compress (create the archive)
vtells tar to be verbose, so you know at which point it is working, it has a performance impact
ftells 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.
endUsing 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
Code Snippets
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.
endContext
StackExchange DevOps Q#943, answer score: 7
Revisions (0)
No revisions yet.