TIL - How to remove older backups from disk to save space
We keep database backups of a local monitoring system which grows twice in size every 2 months. Therefore, removing older backups is sometimes missed resulting in a shortage of disk space.
We keep the most recent files in a directory with the following shell script -
#!/bin/bash
/bin/ls -t /data/backups/*.sql.gz | tail +14 | xargs rm