I have an automated deployer script, which takes a git commit to a certain branch, compiles and uploads the archived binary objects to cloud (S3). Later on, the script logs into an EC2 instance and downloads the archives and executes/starts the project/server.
So far, this is working flawlessly. Recently, I've run into disk space issues. Since I am also storing logs and maintaining current/previous working commits, my directory structure is something like:
/path
/current/ <- symlink
/prev/ <- symlink
/HASH00001/
/HASH00002/
/HASH00003/
/HASH00004/
/HASH00005/
/.../
/.../
/HASH0000n/
/some.log
/some.log.1
/some.log.2.gz
/...
For the sake of maintenance, I want to delete all the subdirectories in /path
which are the specific git commit's SHA value. But, there is a caveat that the directories which are being pointed to by current
and prev
symlinks should not get deleted.
So far, I am doing this manually on whichever machine facing the storage issue. I'd prefer my deploy script to take care of this step as well.
I was using ls
command and sorting the results based on last access timestamp:
ls -drt | head -n -4
and piping xargs rm -rf
to it.
I am now thinking of modifying it so that only the directory names of length exactly 40 characters would be listed, and then remove the dirs. symlinked to current
and prev
.
Can I get some pointers as to how I can achieve the same!