New Post has been published on http://blog.giuseppeurso.net/bash-script-one-tar-gz-archive-from-each-subfolder/index.html
Bash Script: one tar gz archive from each subfolder.
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 give 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















