-
Notifications
You must be signed in to change notification settings - Fork 1
/
do_full_backup.sh
executable file
·62 lines (49 loc) · 1.74 KB
/
do_full_backup.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
#!/bin/bash
SOURCE_FOLDER="/opt/data/backup/backup_folders"
OUTPUT_FOLDER="/opt/data/backup/backup_data"
CATALOGE_FOLDER="/opt/data/backup/backup_cataloge"
BACKUP_NAME="full_backup"
MAIL="[email protected]"
MAX_SLICE_SIZE="45G"
BZIP_LEVEL="6"
LOGFILE="$(mktemp -t dar_output_XXX.txt)"
DATE="$(date +%Y-%m-%d)"
TIME="$(date +%H-%M)"
MESSAGE=""
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}/"
fi
if [ ! -z "$MESSAGE" ]; then
echo $MESSAGE; exit 1
fi
DAR_MESSAGE="$(dar -Q -v -s $MAX_SLICE_SIZE -zbzip2:$BZIP_LEVEL -D -R $SOURCE_FOLDER -c "${OUTPUT_FOLDER}/${BACKUP_NAME}_${DATE}_${TIME}" -@ "${CATALOGE_FOLDER}/${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. Detailed dar output see attached file.
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 file.
Please make sure to safely store the .dar files
Best regards,
your backup-script
---------
$DAR_MESSAGE
EOM
fi