Results 1 to 3 of 3
Hello
This may be a simple thing to do but I'm a little stuck !
I have the following directory structure
www/
www/folder1
www/folder2
www/folder3
Each folder (1,2 and 3) ...
- 05-04-2007 #1Just Joined!
- Join Date
- May 2006
- Posts
- 10
Recursively Compress Directories for Backup
Hello
This may be a simple thing to do but I'm a little stuck !
I have the following directory structure
www/
www/folder1
www/folder2
www/folder3
Each folder (1,2 and 3) has many subfolders and file within.
I want to be able run a shell script that goes through the www folder and makes compressed tar archives of each folder with that foldername ready for backup offsite
So the result would be
www/folder1.tar.gz
www/folder2.tar.gz
www/folder3.tar.gz
The original folders would be left intact and untouched as they are used by others.
I know how to do one folder at a time but not all the diretories from one script.
Thanks in advance
- 05-05-2007 #2Linux Newbie
- Join Date
- Sep 2005
- Location
- CZ
- Posts
- 164
Perhaps this could be of some use:
For names beginning with "." you have to find an alternative thoughCode:#! /bin/bash for D in www/* do if [ -d "$D" ] then echo "Directory $D" tar -cvjf "`dirname "$D"`/`basename "$D"`.tar.bz2" "$D" else echo "Not a directory $D" fi done
- 05-06-2007 #3Just Joined!
- Join Date
- Jun 2005
- Posts
- 2
A nice script. Just replace the www/* with `find .` to see hidden files, directories, etc.
Try this one also ~~
This will work for folders with spaces in them too!Code:#!/bin/bash DIR=/var/www LS=`which ls` #cd $DIR echo $LS | bash | while read x; do if [ -d "$x" ] then echo "backing up $x..." tar -cjf "$x".tar.gz "$x" fi done


Reply With Quote