forked from bit-team/user-callback
-
Notifications
You must be signed in to change notification settings - Fork 0
/
user-callback.notify
executable file
·116 lines (107 loc) · 5.7 KB
/
user-callback.notify
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#!/bin/bash
# Example script for user-callback
# user-callback is a script called by backintime (http://backintime.le-web.org)
# before, during and after a backup.
# Copyright (c) 2014 Fabrizio Marana
# This program is free software: you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free Software
# Foundation, either version 3 of the License, or (at your option) any later version.
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
# See the GNU General Public License for more details.
# You DID NOT receive a copy of the GNU General Public License along with this
# program as the license is bigger then this program.
# Therefore, see http://www.gnu.org/licenses/ for more details.
# Note:
# To allow the notify-send "expire-time" parameter to work,
# follow http://www.webupd8.org/2014/04/configurable-notification-bubbles-for.html
# To allow mail to be sent, the "mailutils" package must be installed and
# configured and there must be a MTA (Mail Transport Agent) e.g. "postfix"
# or "exim4" installed and configured:
# sudo apt-get install mailutils
# sudo apt-get install postfix
# https://www.google.com/search?q=linux+configure+mailutils
# Version 0.2 DD 2014/11/08 Change as much fixed text to variables to allow
# others to modify more easily
# Polish code to make it more readable
# TO DO: Use rsync instead of cpio
### Init ###
# You need to configure this before using this script
declare szBackInTimeEMailAddress="" #if empty, no mail will be sent on error
declare szBackupVolume="" #if empty, no finalising will be performed
# BackInTime passes arguments on the command line. Name them for clarity.
declare iBackInTimeProfileID="$1"
declare szBackInTimeProfileName="$2"
declare iBackInTimeStatus="$3"
declare iBackInTimeSnapshotID="$4"
declare szBackInTimeSnapshotName="$5"
### main ###
case $iBackInTimeStatus in
1) ## Backup Starting ##
# Here you should put commands that you need JUST before the backup begins, E.g.:
# stop daemons/services, ...
notify-send --urgency=LOW --icon=face-plain "BackInTime" \
"Starting backup '${iBackInTimeProfileID}:${szBackInTimeProfileName}'..."
;;
2) ## Backup Finished ##
notify-send --urgency=NORMAL --icon=face-laugh "BackInTime" \
"Finished backup '${iBackInTimeProfileID}:${szBackInTimeProfileName}' completely!"
# Here you should put the commands that you need after the backup ends, E.g.:
# (Probably the reverse of the 1) section)
# allow the user to try again later, ...
;;
3) ## Backup Finishing ##
notify-send --urgency=NORMAL --icon=face-cool --expire-time=4000 "BackInTime" \
"Finishing backup '${iBackInTimeProfileID}:${szBackInTimeProfileName}'\nfor snapshot '${iBackInTimeSnapshotID}:${szBackInTimeSnapshotName}'..."
# Here you should put the commands that you need to do just before the backup finishes:
# Copying extra files,
# writing to logs, ...
;;
4) # An error occurred: $iBackInTimeSnapshotID contains the error number
declare -r iBackInTimeError=$iBackInTimeSnapshotID
declare szBackInTimeErrorMessage="BackInTime Error: "
declare szBackInTimeExtendedErrorMessage=""
# We're notifying the user on-screen and emailing the log file
# using the mailutils package regardless of the kind of error
case $iBackInTimeError in
1) ## Application not configured ##
szBackInTimeErrorMessage=$szBackInTimeErrorMessage" Application not configured!"
;;
2) ## Application already Running ##
szBackInTimeErrorMessage=$szBackInTimeErrorMessage" BackInTime is already running!"
szBackInTimeExtendedErrorMessage="\n\nPlease ensure you don't have an automatic backup and a manual backup both running at once."
;;
3) ## No snapshot Directory ##
szBackInTimeErrorMessage=$szBackInTimeErrorMessage" BackInTime can’t find the snapshots directory!"
szBackInTimeExtendedErrorMessage="\n\n(Is it on a removable drive which was detached/unmounted in error?)"
;;
4) ## Snapshot already exixsts ##
szBackInTimeErrorMessage=$szBackInTimeErrorMessage" A snapshot for 'now' already exists!"
;;
esac # Error
notify-send --urgency=CRITICAL --icon=face-angry "BackInTime Error" "$szBackInTimeErrorMessage$szBackInTimeExtendedErrorMessage"
# only send mail if the e-mail address is not empty
if [ -n "$szBackInTimeEMailAddress" ] && \
[ "x$(which mail)" != "x" ] && \
[ -x $(which mail) ]; then
mail --subject="$szBackInTimeErrorMessage$(date +%Y-%m-%d)" --to "$szBackInTimeEMailAddress"<~/.local/share/backintime/takesnapshot_.log
fi
;;
5) ## backintime-qt4 (GUI) started ##
# Here you can put things that need to be done when launching the GUI
;;
6) ## backintime-qt4 (GUI) closed ##
# Here you can put things that need to be done when closing the GUI
;;
7) ## Mount drives ##
# Here you should place custom mount commands which will be called everytime
# the GUI or command line tool is started or the profile is switched in GUI
;;
8) ## Unmount the drives ##
# Here you should place unmount scripts for the drive you mounted in 7)
;;
esac #Status