forked from nriitala/conf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
manage-vim-backups.sh
executable file
·32 lines (27 loc) · 1010 Bytes
/
manage-vim-backups.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#!/bin/sh
####################################################
# Original author for vim backup manager script: #
# Ari Simonen #
####################################################
DIR="/home/niko/.vim-backup"
# How old files we want to remove?
THISOLD=$((`date +%m` - 1))
# How many versions we want to keep?
VERSIONCOUNT=5
LOGFILE="$DIR/removelog_`date +%y%m%d`-`date +%H%M`"
FILUT=`ls $DIR|sed "s/\(.*\)_\([0-9]\{6\}\)-\([0-9]\{4\}\)/\\1/"|sort|uniq`
echo `ls $DIR` > $LOGFILE
for i in $FILUT; do
COUNT=`ls $DIR/$i*|wc -l`
if [ $COUNT -gt $VERSIONCOUNT ]; then
GTFO=`ls $DIR/$i*|sort`
for j in $GTFO; do
MM=`echo $j|sed "s/\(.*\)_\([0-9]\{2\}\)\([0-9]\{2\}\)\([0-9]\{2\}\)-\([0-9]\{4\}\)/\\3/"`
if [ $MM -lt $THISOLD -a $COUNT -gt $VERSIONCOUNT ]; then
echo "let me remove $j for you" > $LOGFILE
/bin/rm $j
fi
COUNT=$(($COUNT - 1))
done
fi
done