-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrsnapshot_logged.sh
executable file
·54 lines (46 loc) · 1.46 KB
/
rsnapshot_logged.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
#!/bin/sh
# cd "$(dirname "$0")";
# CWD="$(pwd)"
# echo $CWD
# TODO: Copy then delete mail messages: cron uses the "mail" command to record any stderr output produced.
# See also `grep rsnapshot /var/log/syslog`
OUTFILE=/var/log/linuxpreinstall.rsnapshot_logged.sh.out
TMPFILE=/var/log/linuxpreinstall.rsnapshot_logged.sh.tmp
LOG=/var/log/linuxpreinstall.rsnapshot_logged.sh.log
python3 /opt/bin/rsnapshot_logged.py "$1" 1>$OUTFILE 2>$LOG
RESULT_RC=/opt/etc/rsnapshot-generated.rc
if [ ! -f "$RESULT_RC" ]; then
# ^ generated by rsnapshot_logged.py
echo "Error: missing $RESULT_RC" >> $LOG
fi
. $RESULT_RC
if [ -z "$snapshot_root" ]; then
echo "Error: no snapshot_root in $RESULT_RC" >> $LOG
return 2
fi
if [ -z "$backup_drive" ]; then
echo "Error: no backup_drive in $RESULT_RC" >> $LOG
return 3
fi
if [ -z "$dst_logs" ]; then
echo "Error: no dst_logs in $RESULT_RC" >> $LOG
return 3
fi
if [ ! -d "$dst_logs" ]; then
echo "Error: rsnapshot_logged.py did not create the dst_logs folder \"$dst_logs\"." >> $LOG
return 3
fi
echo "cp $LOG $dst_logs/"
cp $LOG "$dst_logs/" 1>>$OUTFILE 2>>$TMPFILE
# ^ TMPFILE since can't read & write same file in same pipeline!
if [ -f "$TMPFILE" ]; then
cat $TMPFILE >> $LOG
rm $TMPFILE
fi
echo "cp $OUTFILE $dst_logs/"
cp $OUTFILE "$dst_logs/" 1>>$TMPFILE 2>>$LOG
# ^ TMPFILE since can't read & write same file in same pipeline!
if [ -f "$TMPFILE" ]; then
cat $TMPFILE >> $OUTFILE
rm $TMPFILE
fi