New User? Register here - Existing Users: Username: Password: [Advanced Login]

 

 

Current Poll

Your preferred Interactive shell?









( 1337 votes ~ 14 comments )

 

Weblog entry #8 for blackm

rotating backup files
Posted by blackm on Sun 2 Oct 2005 at 20:31
Tags: none.
If you have a directory in which are all you backups (one file per day) you can use the following bash code to rotate these files.
if [ `ls -1 $DIR | wc -l` -ge 30 ]
then
    OLD=`expr \`ls -t1 $DIR | wc -l\` - 30`

    for FILE in `ls -t1 $DIR | tail -n $OLD`
    do
        rm $FILE
    done
fi

This will delete the oldest file if there are more then 30 file but always keep 30 files (if the backup process fail, old backups are not going to be deleted).

 

 

 

Flattr