I guess you have many back_YY.MM.DD folders with different date.
rootpath="/" # you can update here, if the backup folder are not under /
cd $rootpath
ls -l back_* |awk '/^d/ {print $NF}' |while read dir
do
cd ${dir}
ls -l |awk '/^d/ {print $NF}' |while read subdir
do
tar cvf - ${subdir} |gzip > ${subdir}_${dir#*_}.tar.gz # or replace by below command, if you have gtar
# gtar zcvf ${subdir}_${dir#*_}.tar.gz ${subdir}
done
cd $rootpath
done
Yes. I have many backups with different dates and in each day is adding more.
I tested your script and something strange are happening:
al folders beginning with back are processed ("back" "back.somename")
on every pass i get a message about line 7:
"line 7: cd: back1: No such file or directory"
Probably because of that:
all archives are made in root folder and not in it's own folder
all files from subfolders are not deleted.
archives contain all subfolders not just own folders: backup1_YYMMDD.tar.gz contain all subfolders (ex. backup1/, backup2/, etc) instead just backup1/* subfolder.
Even so, I can use your script as it is. Is a great time saving. Thanks again for your reply.
I made little modification on rcdcwayx code, and is working fine now:
rootpath="/somefolder" # you can update here, if the backup folder are not under /
cd $rootpath
ls -l|grep back_ |awk '/^d/ {print $NF}' |while read dir
do
cd ${rootpath}/${dir}
ls -l |awk '/^d/ {print $NF}' |while read subdir
do
tar cvf - ${subdir} |gzip > ${subdir}_${dir#*_}.tar.gz # or replace by below command, if you have gtar
# gtar zcvf ${subdir}_${dir#*_}.tar.gz ${subdir}
done
cd $rootpath
done
Just "back_" folders are processed, all tars are created now in own "back" folders and contain only right subfolder. I can�t understand why cd command doesn�t work without $rootpath variable ("line 7: cd: back1: No such file or directory" are displayed and all script go crazy).
Still I don�t know how to delete archived files and subfolders and how to avoid archival of already archived folders on next script run. Maybe changing the name of main folder from �back_� to �back.� after archiving process end, may by a solution.
cd $rootpath
ls -l|grep back_ |awk '/^d/ {print $NF}' |while read dir
do
cd ${rootpath}/${dir}
ls -l |awk '/^d/ {print $NF}' |while read subdir
do
tar cvf - ${subdir} |gzip > ${subdir}_${dir#*_}.tar.gz # or replace by below command, if you have gtar
# gtar zcvf ${subdir}_${dir#*_}.tar.gz ${subdir}
rm -rf $subdir
done
cd $rootpath
done
rename back_ back. back_*
All subfolders are deleted and main folders are renamed to not be procesed on next run.