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:

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

Example. let’s say that you have a webserver whit an usual directory structure for clients, for example:
/var/www/client1
/var/www/client2

/var/www/clientx
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

Giuseppe 

Incoming search terms:

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

Author: Giuseppe Urso

Giuseppe lives in Haarlem now with his shiny dog, Filippa In 1982 received his first home computer, a Commodore 64, followed by Datasette and a 1541 Floppy Disk Drive. In 1999 he installed his first Linux distro (LRH6). In 2006 he switched to Debian as favourite OS. Giuseppe Urso actively sustains the Free Software Fundation and his founder Richard Mattew Stallman, he speaks to people trying to convince them to join the fight now, and about how important is to use Free Software only. He has a job as Infra Specialist at Hippo Enterprise Java Cms an Open Source Enterprise class Content Management System, one of the coolest company ever, in Amsterdam. He's always ready to install Debian on other people computers for free.

One thought on “Bash Script: one tar gz archive from each subfolder.”

Leave a Reply

Your email address will not be published. Required fields are marked *

 

This site uses Akismet to reduce spam. Learn how your comment data is processed.