-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtobackup-report
executable file
·92 lines (71 loc) · 1.75 KB
/
tobackup-report
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
#!/bin/sh
##############################################################################
# tobackup - A simple unix-style backup tool
# Author : Thomas Martin <[email protected]>
##############################################################################
usage() {
cat <<EOT >&2
Usage: $0 [OPTION] HOST EMAIL
-f FILE : specify alternative config file (default /usr/local/etc/backuprc)
-d DEPTH : print DEPTH levels of last backup content
HOST : host referenced in config file
EMAIL : where to send reports
EOT
}
conffile="/usr/local/etc/backuprc"
while getopts 'f:d:' opt; do
case $opt in
f)
conffile=$OPTARG
;;
d)
backup_detail_depth=$OPTARG
;;
esac
done
shift $((OPTIND-1))
if [ $# -ne 2 ]; then
usage
exit 1
fi
. $conffile
backuphost=$1
email=$2
mailbody=`mktemp /tmp/mailbody.XXXXXX`
exec >$mailbody
cat <<EOT
======================
Backup archives report
======================
EOT
print_size() {
size=`du -sh $1 | cut -f 1`
mtime_timestamp=$(stat -c "%Y" $1)
mtime=$(date -d @$mtime_timestamp '+%Y/%m/%d')
printf "%s = %s\n" $mtime $size
}
for subdir in daily weekly monthly; do
fullsubdir="/home/backup/$backuphost/$subdir"
if [ -d $fullsubdir ]; then
echo "Archives $subdir :"
cd $fullsubdir
for i in [0-9]; do
print_size $i
done
echo
fi
done
print_backup_detail() {
backuphost=$1
depth=$2
cat <<EOT
Last backup (first-level directories)
=====================================
EOT
cd /home/backup/$backuphost/daily/0
find . -maxdepth $depth -type d
}
if [ $backup_detail_depth ]; then
print_backup_detail $backuphost $backup_detail_depth
fi
mail -s "[$backuphost] backup report" $email <$mailbody