An implementation of @Krzysztof Stasiak description could be like this.
First make some test directories:
cd /backup mkdir Full/20170{1,7}02 mkdir Incremental/2017010{1..9} mkdir Incremental/2017070{1..9} And the script:
#! /bin/bash cd /backup for P in Full Incremental; do cd $P for D in *; do [ $(date -d '-90 days' +%Y%m%d) -gt $D ] && rm -rf $D done cd .. done To test, you can put an echo before rm to see what is going to be done but without doing it.
Here we just cd to the main directory and start a for-loop for the two diretories:
cd /backup for P in Full Incremental; do then cd into the "periode" directory:
cd $P then do a forloop over all directories:
for D in *; do if today minus 90 days is greater-than -gt the directory $D:
[ $(date -d '-90 days' +%Y%m%d) -gt $D ] then delete the directory:
&& rm -rf $D You can also write it like:
if [ $(date -d '-90 days' +%Y%m%d) -gt $D ]; then rm -rf $D fi Consider using a standard backup software instead. It could be Bacula.