-
Notifications
You must be signed in to change notification settings - Fork 1
/
do_inc_backup_ref-full.sh
executable file
·89 lines (63 loc) · 2.55 KB
/
do_inc_backup_ref-full.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
#!/bin/bash
# Which folder cotains the data to be backuped
SOURCE_FOLDER="/opt/data/backup/backup_folders"
# Folder to place the dar backup files (those files must be saved to a secure place like a BluRay Dics)
OUTPUT_FOLDER="/opt/data/backup/backup_data"
# Folder containing all dar-cataloges for both full and incremental backups
CATALOGE_FOLDER="/opt/data/backup/backup_cataloge"
# Backup base name
BACKUP_NAME="backup"
# Receiver of statusmail
MAIL="[email protected]"
# Maximum filesize for each dar-file (default 20G)
MAX_SLICE_SIZE="20G"
# Compression Level for Backup (0-9, default 6)
BZIP_LEVEL="6"
# reference backup is last incremental (inc) or the last full (full) backup (
REFERENCE="full"
LOGFILE="$(mktemp -t dar_output_XXX.txt)"
DATE="$(date +%Y-%m-%d)"
TIME="$(date +%H-%M)"
MESSAGE=""
LAST_CATALOGE="$(ls -1 ${CATALOGE_FOLDER}/${REFERENCE}_${BACKUP_NAME}_cataloge* 2>/dev/null | sort -r | head -n1 | sed 's/\.[0-9]\{1,\}\.dar$//')"
if [ ! -e "$LAST_CATALOGE.1.dar" ]; then
MESSAGE="ERROR: No old dar cataloge found. Wrong backup name or no full backup available?"
fi
if [ ! -r $SOURCE_FOLDER ]; then
MESSAGE="ERROR: Source folder does not exist or is not readable."
fi
if [ ! -w $OUTPUT_FOLDER ]; then
MESSAGE="ERROR: Output folder does not exist or is not writeable."
fi
if [ ! -w $CATALOGE_FOLDER ]; then
MESSAGE="ERROR: Cataloge folder does not exist or is not writeabe."
fi
if [ "$(ls -A ${OUTPUT_FOLDER}/${BACKUP_NAME}* 2>/dev/null)" ]; then
MESSAGE="ERROR: At least one file with the same basename exists already in ${OUTPUT_FOLDER}/\nMaybe the old backup files have not been removed?"
fi
if [ ! -z "$MESSAGE" ]; then
echo $MESSAGE; exit 1
fi
DAR_MESSAGE="$(dar -Q -v -s $MAX_SLICE_SIZE -zbzip2:$BZIP_LEVEL -A $LAST_CATALOGE -D -R $SOURCE_FOLDER -c "${OUTPUT_FOLDER}/inc_${BACKUP_NAME}_${DATE}_${TIME}" -@ "${CATALOGE_FOLDER}/inc_${BACKUP_NAME}_cataloge_${DATE}_${TIME}" &> $LOGFILE)"
ERROR_CODE=$?
if [ $ERROR_CODE -ne 0 ]; then
mutt -s "Backup -($BACKUP_NAME)- exited with error(s)" -a $LOGFILE -- $MAIL <<EOM
Hi Admin,
the backup for $SOURCE_FOLDER exited with error code $ERROR_CODE!
Please check on addtional actions and the attached logfile.
Best regards,
your backup-script
------------
$DAR_MESSAGE
EOM
else
mutt -s "Backup -($BACKUP_NAME)- was successful" -a $LOGFILE -- $MAIL <<EOM
Hi Admin,
the backup for $SOURCE_FOLDER went fine. Details in the attached logfile.
Please make sure to safely store the .dar files
Best regards,
your backup-script
------------
$DAR_MESSAGE
EOM
fi