On my debian 9.4 machine I have a script that automatically compresses & backups up all my files in a srv/ with the date in the name xx-xx-xxxx.tar. It is moved to my backups/ directory.
I would like to limit the amount of .tar files (backups) to 10 in the folder, and remove the oldest .tar file every time a new tar is created.
What would be the best way of going about this? Here is my script:
#!/bin/bash #Purpose = Backup of Important Data #Created on 17-1-2012 #Author = Hafiz Haider #Version 1.0 #START TIME=`date +%b-%d-%y` # This Command will add date in Backup File Na$ FILENAME=backup-$TIME.tar.gz # Here i define Backup file name format. SRCDIR=/srv/daemon-data # Location of Important Data Directo$ DESDIR=/backups # Destination of backup file. tar -cpzf $DESDIR/$FILENAME $SRCDIR #END