Project

General

Profile

Paste
Download (722 Bytes) Statistics
| Branch: | Revision:

root / bin / flush-files.sh @ d52a5b2f

1
#!/bin/sh
2

    
3
help="# ARGS: number of files to keep, [email address]\n
4
# usage: flush files from a folder except a number equal to argument."
5

    
6
# Check if scripts-utils.sh is imported.
7
if [ -z $scripts_utils ] ; then
8
    echo "Import of scripts-utils.sh required."
9
    . scripts-utils.sh
10
fi
11

    
12
check_arguments $# 1 "$help"
13

    
14
backups_number=`ls | wc -l`
15
let "number_of_backups_to_delete = backups_number - $1" > /dev/null
16

    
17
if [ $number_of_backups_to_delete -gt 0 ] ; then
18
    ls | head -$number_of_backups_to_delete | xargs rm
19
else
20
    if [ ! -z $2 ] ; then
21
        dir=`pwd`
22
        echo "There are not enough files in $dir to Flush it. Check if backup script works fine." | mail -s "[db] $dir has a backup problem" $2
23
    fi
24
fi