-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpar2stats.sh
More file actions
executable file
·72 lines (65 loc) · 1.68 KB
/
par2stats.sh
File metadata and controls
executable file
·72 lines (65 loc) · 1.68 KB
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/bin/busybox ash
#
# Script to show par2 archives or duplicates stats
#
# Call it like this:
#
# $ par2stats.sh [OPTIONS]
# (without arguments) to show stats for all files in all monthly backups
#
# $ par2stats.sh [OPTIONS] 1
# to show stats for all files in last 1 monthly backups
#
# $ par2stats.sh [OPTIONS] 3 2
# to show stats for all files in backups which are older than 2 but newer than 3 months old
#
# Options are:
# -q to be less verbose regarding progress
. "$(dirname "$0")/common.sh"
if test "$1" = "-q"; then
quiet_progress=1
shift
fi
cond2="AND created<strftime('%Y-%m', 'now')"
if test ! -z "$1"; then
cond1="AND created>=strftime('%Y-%m', 'now', '-$1 months')"
fi
if test ! -z "$2"; then
cond2="AND created<strftime('%Y-%m', 'now', '-$2 months')"
fi
sql1=" SELECT count(*)
FROM history
WHERE type='f'
AND freq<2 $cond1 $cond2;"
sql=" SELECT dirname || filename || '/' || created,
'$BACKUP_TIME_SEP' || deleted
FROM history
WHERE type='f'
AND freq<2 $cond1 $cond2
ORDER BY dirname;"
echo "total files to check:"
echo "$sql1" | $SQLITE
export LC_ALL=POSIX
echo "$sql" | $SQLITE | (
a=0
b=0
while IFS="$NL" read -r f; do
filepart="$BACKUP_MAIN/${f%%|*}"
fileend="${f##*|}"
filename="$filepart$fileend"
# if test "$filename" -ef "$filepart.bak"; then
# # *.bak file is hardlinked to original => remove
# rm -f "$filepart.bak"
# fi
a=$(expr $a + 1)
if test -f "$filepart.bak" || test -f "$filepart.par2"; then
# *.bak or *.par2 file found
b=$(expr $b + 1)
fi
if test -z "$quiet_progress" && expr $a : '.*00$' >/dev/null; then
echo "checked [$a], secured [$b] files"
fi
done
prc=$(( b * 100 / a ))
echo "$b out of $a files secured ($prc%)"
)