The key is to convert the date folder names into Unix Epoch time so you can easily compare them.
#!/bin/bash
dataDir="/abs/path/to/data"
recentDir="/abs/path/to/data_recent"
daysToKeep=90
minKeepEpoch=$(date --date "$daysToKeep days ago" +%s)
# Create new links for folders that are within $daysToKeep
while IFS= read -r -d $'\0' dir; do
dirName=${dir##*/}
dirEpoch=$(date --date ${dirName//./} +%s)
(( dirEpoch >= minKeepEpoch )) && ln -s -t "$recentDir" "$dir"
done < <(find "$dataDir" -mindepth 1 -maxdepth 1 -type d -print0)
# Remove links that are older than $daysToKeep
while IFS= read -r -d $'\0' link; do
linkName=${link##*/}
linkEpoch=$(date --date ${linkName//./} +%s)
(( linkEpoch < minKeepEpoch )) && rm "$link"
done < <(find "$recentDir" -mindepth 1 -maxdepth 1 -type l -print0)
Proof of Concept
Note that ./data_recent was pre-populated with an outdated link that will be removed
$ tree ./data
./data
├── 2010.01.01
│ ├── f1
│ └── f2
├── 2020.02.27
│ ├── f1
│ └── f2
├── 2020.02.28
│ ├── f1
│ └── f2
├── 2020.05.27
└── 2020.05.28
└── f1
12 directories, 0 files
$ tree ./data_recent/
./data_recent/
└── 2010.01.01 -> /abs/path/to/data/2010.01.01
1 directory, 0 files
$ ./syncFolders.sh
$ tree ./data_recent/
./data_recent/
├── 2020.05.27 -> /abs/path/to/data/2020.05.27
└── 2020.05.28 -> /abs/path/to/data/2020.05.28
2 directories, 0 files
data_recent/. (ln -s). Then it's just a matter of looping over the new directories indata/and adding new links indata_recent/and looping over the links indata_recent/and removing links for any older than 90-days. In either case you can parse the directory name and then create a date (in seconds since epoch) withdate -d "folder_date" +%s. You get the number of seconds for 90 days ago withdate -d "90 days ago" +%sfind data/ -type f -newermt "$(date -d "90 days ago" "+%F %R")":-)