Hi,
I'm trying to achieve a script which looks for expired backups in a folder and deletes them BUT keeps at least 2 of the youngest backups in spare - even if they would be older then ${EXPIRY}
Files in the backup folder would look like this - and yes, they could also contain spaces:
WS-01_-_2014-06-09_21-33-00.xva
WS-01_-_2014-06-10_21-33-00.xva
WS-01_-_2014-06-11_21-33-00.xva
WS-02_-_2014-06-09_21-33-00.xva
WS-02_-_2014-06-10_21-33-00.xva
WS-02_-_2014-06-11_21-33-00.xva
WS-03_-_2014-06-09_21-33-00.xva
WS-03_-_2014-06-10_21-33-00.xva
WS-03_-_2014-06-11_21-33-00.xva
WS-05_-_2014-06-09_21-33-00.xva
WS-05_-_2014-06-10_21-33-00.xva
WS-05_-_2014-06-11_21-33-00.xva
Any idea how I could achieve this with minimum code, since the
Thanks
I'm trying to achieve a script which looks for expired backups in a folder and deletes them BUT keeps at least 2 of the youngest backups in spare - even if they would be older then ${EXPIRY}
Code:
EXPIRY="3"
while read FILE; do
#stat -f "%-10m %40N" "${FILE}"
echo "delete ${FILE}"
done <<< "$( find ${backup_dir} -type f -mtime +${EXPIRY} | sort -d )" | awk 'NR > 2 {print $2}'
Files in the backup folder would look like this - and yes, they could also contain spaces:
WS-01_-_2014-06-09_21-33-00.xva
WS-01_-_2014-06-10_21-33-00.xva
WS-01_-_2014-06-11_21-33-00.xva
WS-02_-_2014-06-09_21-33-00.xva
WS-02_-_2014-06-10_21-33-00.xva
WS-02_-_2014-06-11_21-33-00.xva
WS-03_-_2014-06-09_21-33-00.xva
WS-03_-_2014-06-10_21-33-00.xva
WS-03_-_2014-06-11_21-33-00.xva
WS-05_-_2014-06-09_21-33-00.xva
WS-05_-_2014-06-10_21-33-00.xva
WS-05_-_2014-06-11_21-33-00.xva
Any idea how I could achieve this with minimum code, since the
awk 'NR > 2 {print $2}' doesn't do the job rightThanks