Bash Script: one tar gz archive from each subfolder.

my treasure, missing link between dogs and unicorns, i'll never get used to such a beauty. My actual best friend. Her nose stinks of a mixture of out-of-date parmigiano and various other cheeses.
my Filippa

Hi all, this is a backup tool to be used in for automated or manual backup. What this small script does is creating one tar.gz archive for each subdirectory found starting from a given directory.

It takes just two arguments: where to start from, where to save the new created archives.

The goal is “KEEP IT SIMPLE”, so you can easily adapt this t your systems. You can for instance, hardcode the two args so you can use it for a specific duty (web folders backup /var/www or whatever).

Here you are:

cd $1
for dir in */
base=$(basename "$dir")
tar -czf "$2/${base}.tar.gz" "$dir"
echo "compressing $2/${base}.tar.gz $dir";

Example. let’s say that you have a webserver whit an usual directory structure for clients, for example:
and so.
If you wanted a separated tar gz archive for each client subfolder you should use this script this way:
./multitar /var/www /backups


Have a nice weekend


Incoming search terms:

  • closely5gz (1)
  • halfway6x5 (1)
  • noneupp (1)
  • smallest2rz (1)
  • south8yg (1)
(Visited 1,302 times, 1 visits today)