-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrsync-backup
108 lines (103 loc) · 4.16 KB
/
rsync-backup
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
#!/bin/bash
# Make backups with rsync and echo the output to journald
# Send notifications to a matrix server (via separate matrix-client-script)
# Author: Zjemm
# Email: mail [at] sjemm {dot} net
# Please use/share/comment/reference
# Date: 23-08-2017
# Version 0.4
# Requirements: fonts-symbola
# Usage: run this script with arguments
# Example: ./rsync-backup /home/music /backup/
# Where "/home/music" will be $1 and "/backup/"" will be $2
# Set a username to notify for error's
# For example all messages may be muted in a room, except for "User Mentions"
# This way you will only be notified when there is an error using the username here
USER=UsertoNotify
# Create a VAR of the rsync output to be used in the notification message
OUTPUT=$(rsync -a --delete $1 $2)
case $? in
0)
echo "Backup of $1 Success" | systemd-cat -t rsync -p info
notify-matrix "✅ Backup of $1 Success"
;;
1)
echo "Backup of $1 Failed - Syntax or usage error" | systemd-cat -t rsync -p info
notify-matrix "⛔ $USER: Backup of $1 Failed"
;;
2)
echo "Backup of $1 Failed - Protocol incompatibility" | systemd-cat -t rsync -p info
notify-matrix "⛔ $USER: Backup of $1 Failed"
;;
3)
echo "Backup of $1 Failed - Errors selecting input/output files, dirs" | systemd-cat -t rsync -p info
notify-matrix "⛔ $USER: Backup of $1 Failed"
;;
4)
echo "Backup of $1 Failed - Requested action not supported: an attempt was made to manipulate 64-bit files on a platform that cannot support them; or an option was specified that is supported by the client and not by the server." | systemd-cat -t rsync -p info
notify-matrix "⛔ $USER: Backup of $1 Failed"
;;
5)
echo "Backup of $1 Failed - Error starting client-server protocol" | systemd-cat -t rsync -p info
notify-matrix "⛔ $USER: Backup of $1 Failed"
;;
6)
echo "Backup of $1 Failed - Daemon unable to append to log-file" | systemd-cat -t rsync -p info
notify-matrix "⛔ $USER: Backup of $1 Failed"
;;
10)
echo "Backup of $1 Failed - Error in socket I/O" | systemd-cat -t rsync -p info
notify-matrix "⛔ $USER: Backup of $1 Failed"
;;
11)
echo "Backup of $1 Failed - Error in file I/O" | systemd-cat -t rsync -p info
notify-matrix "⛔ $USER: Backup of $1 Failed"
;;
12)
echo "Backup of $1 Failed - Error in rsync protocol data stream" | systemd-cat -t rsync -p info
notify-matrix "⛔ $USER: Backup of $1 Failed"
;;
13)
echo "Backup of $1 Failed - Errors with program diagnostics" | systemd-cat -t rsync -p info
notify-matrix "⛔ $USER: Backup of $1 Failed"
;;
14)
echo "Backup of $1 Failed - Error in IPC code" | systemd-cat -t rsync -p info
notify-matrix "⛔ $USER: Backup of $1 Failed"
;;
20)
echo "Backup of $1 Failed - Received SIGUSR1 or SIGINT" | systemd-cat -t rsync -p info
notify-matrix "⛔ $USER: Backup of $1 Failed"
;;
21)
echo "Backup of $1 Failed - Some error returned by waitpid()" | systemd-cat -t rsync -p info
notify-matrix "⛔ $USER: Backup of $1 Failed"
;;
22)
echo "Backup of $1 Failed - Error allocating core memory buffers" | systemd-cat -t rsync -p info
notify-matrix "⛔ $USER: Backup of $1 Failed"
;;
23)
echo "Backup of $1 Failed - Partial transfer due to error" | systemd-cat -t rsync -p info
notify-matrix "⛔ $USER: Backup of $1 Failed"
;;
24)
echo "Backup of $1 Failed - Partial transfer due to vanished source files" | systemd-cat -t rsync -p info
notify-matrix "⛔ $USER: Backup of $1 Failed"
;;
25)
echo "Backup of $1 Failed - The --max-delete limit stopped deletions" | systemd-cat -t rsync -p info
notify-matrix "⛔ $USER: Backup of $1 Failed"
;;
30)
echo "Backup of $1 Failed - Timeout in data send/receive" | systemd-cat -t rsync -p info
notify-matrix "⛔ $USER: Backup of $1 Failed"
;;
35)
echo "Backup of $1 Failed - Timeout waiting for daemon connection" | systemd-cat -t rsync -p info
notify-matrix "⛔ $USER: Backup of $1 Failed"
;;
*)
echo "Backup of $1 Failed - Unknown return code $? from rsync" | systemd-cat -t rsync -p info
notify-matrix "⛔ $USER: Backup of $1 Failed"
esac