# Cells purging question

**URL:** <https://forum.pydio.com/t/cells-purging-question/3087>\
**Category:** Pydio Cells\
**Created:** [February 14, 2020, 6:10pm UTC](https://forum.pydio.com/t/cells-purging-question/3087 "2020-02-14T18:10:06Z")\
**Posts on this page:** 1\
**Showing post:** 18

<div class="post-metadata">

**Author:** ![scott.bentley](https://avatars.discourse-cdn.com/v4/letter/s/3be4f8/32.png) [@scott.bentley](https://forum.pydio.com/u/scott.bentley)\
**Post date:** [February 1, 2022, 10:39pm UTC](https://forum.pydio.com/t/cells-purging-question/3087/18 "2022-02-01T22:39:50Z")

</div>

hey @sbs

I actually wrote a shell script to do this for us. What it does is move/delete the files from the location on disk, and then uses the Cells CLI tool to run a datasource synchronization that repairs the database.I know it’s not the “API based solution” I was hoping for when I posted this question, but it does work well.

This is the script:

```auto
#!/bin/bash
#
# This script will move files older than 30 days to recyclebin
# NOTE files inside folders with a name that starts with "/lts-" will not be moved.
# "lts-" folders are considered "Long Term Storage" and are exempt from this script.
#
shopt -s globstar

if ["$USER" != "pydio"]; then
        echo "Please run this script as pydio user"
        #exit
fi

#Empty the previous recyclebin
rm /home/pydio/recyclebin/*

#Obtain timestamp -30 days
pastdate=$(date -d "$date -30 days" '+%s')
#Loop through all files/folders
for file in /home/pydio/.config/pydio/cells/data/cellsdata/**
        do
                #Use perl to match file paths that do not contain "/lts-"
                match=$(echo "${file}" | perl -0777 -pe 's/^(?:(?!\/lts-).)+$/match/i')
                #Get type, directory | regular file
                filetype=`stat -c %F "$file"`
                #If its a good path and file then
                if ["$match" == "match"] && ["$filetype" == "regular file"]; then
                        #Get the mtime timestamp
                        filemtime=`stat -c %Y "$file"`
                        #If the file mtime is older or equal to the comparison date, delete it
                        if [$filemtime -le $pastdate]; then
                                echo "$file"
                                mv "$file" /home/pydio/recyclebin/
                                #rm "$file"
                        fi
                fi
        done

/home/pydio/cells admin resync --datasource=cellsdata
echo " ****"
echo "Script finished. Please verify cellsdata resync in the logs."
echo " ****"

```

---

_[View the full topic](https://forum.pydio.com/t/cells-purging-question/3087)._
