-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstats.sh
executable file
·102 lines (83 loc) · 2.18 KB
/
stats.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
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#!/bin/busybox ash
#
# Script to show some stats
test -z "$BACKUP_BIN" && BACKUP_BIN="${0%/*}"
. "$BACKUP_BIN/common.sh"
cd "$BACKUP_ROOT"
banner() {
echo ===== ===== "$@" ===== =====
}
if [ "$STATS_HEADERS" = 1 ]; then
echo "To: [email protected]"
echo "Subject: `hostname` backup-stats"
echo
fi
banner uptime
uptime
echo
# banner sensors
# sensors
banner disk usage
sh -c "$STATS_DF"
echo
banner backup stats
test "$STATS_BROWSERS" = 1 && echo " SELECT
dirname AS 'Last backup of browser tabs',
filename,
max(created) AS 'created',
round(julianday('now', 'localtime') - julianday(created), 2) AS 'days ago'
FROM history
WHERE freq = 0
AND dirname LIKE './browsers/%/Sessions/'
GROUP BY dirname;" | $SQLITE -header -column
echo
echo 'Last backup per'
ls "$BACKUP_CURRENT" | while read -r line; do
echo " SELECT
'$line' as 'directory ',
'created' AS 'direction',
max(created) AS 'Last backup',
round(julianday('now', 'localtime') - julianday(max(created)), 2) AS 'days ago'
FROM history
WHERE freq = 0
AND dirname LIKE './$line/%'
UNION ALL
SELECT
'$line',
'deleted' AS 'direction',
max(deleted) AS 'Last backup',
round(julianday('now', 'localtime') - julianday(max(deleted)), 2) AS 'days ago'
FROM history
WHERE freq != 0
AND dirname LIKE './$line/%'
UNION ALL"
done | sed '$d' | $SQLITE -header -column
echo
echo " SELECT
freq,
min(deleted) AS 'oldest file',
round((strftime('%s','now','localtime')-strftime('%s',min(deleted)))*freq/2592000,2) as 'age'
FROM history
WHERE freq != 0
AND freq <= 8640
GROUP BY freq;" | $SQLITE -header -column
if [ "$(echo 'SELECT count(*) FROM bad_new_files' | $SQLITE)" != 0 ]; then
banner bad new files
echo 'SELECT * FROM bad_new_files' | $SQLITE -header -column
fi
echo "DROP INDEX IF EXISTS api" | $SQLITE -header -column
test "$STATS_DU" = 1 || exit 0
echo
echo "Disk usage of each dir"
echo "---- ----- -- ---- ---"
(
echo 'name current data'
(
echo .
ls data
) | xargs -I% echo 'echo "% $(test -e current/% && du -h -d0 current/% | cut -f1) $(du -h -d0 data/% | cut -f1)"' | sh
) | column -t
# echo
# echo "Par2 stats"
# echo "---- -----"
# ~/git/backup3/par2stats.sh -q