-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmcBackapper.sh
More file actions
125 lines (98 loc) · 2.88 KB
/
mcBackapper.sh
File metadata and controls
125 lines (98 loc) · 2.88 KB
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
117
118
119
120
121
122
123
124
#!/bin/bash
# mcBackupper - BETA
# Author: mcaldi - info@marcocaldirola.it
# Version: 0.0.1-Beta
# License: GPL-3.0 license
pushd ./
# >>>>> Parameters to change <<<<<
# @@@ Config file @@@ - Backup config file: this file contains folders to backup
CONFIG_FILE_PATH="/home/mcBackupper/mcBackapper.conf"
# @@@ Log directory @@@ - if EMPTY logs disabled
LOG_DIR="/home/mcBackupper/log/"
# >>>>> END Parameters to change <<<<<
if [ ! -z "$LOG_DIR" ]; then
LOG_FILE=${LOG_DIR}backupper_log_$(date +"%Y_%m_%d_%H_%M").log
echo "using log file: $LOG_FILE"
touch ${LOG_FILE}
echo > ${LOG_FILE}
else
LOG_FILE="/dev/null"
echo "log disabled"
fi
while IFS= read -r line; do
#skip comments '#' at begin of the line
if [[ $line == \#* ]]; then
echo "commented line: $line ... SKIPPED"
continue
fi
#skip empty line
if [ -z "$line" ]
then
echo "$line is empty ... SKIPPED"
continue
fi
from_path=`cut -d '|' -f1 <<< $line`
to_path=`cut -d '|' -f2 <<< $line`
compression=`cut -d '|' -f3 <<< $line`
avoid_delete=`cut -d '|' -f4 <<< $line`
#file_directory=`cut -d '|' -f5 <<< $line`
# Source Path checks
# Check if source path exist
#src_directory_name =""
#src_file_name =""
if [ -e "$from_path" ]; then
if [ -d "$from_path" ]; then
echo "the source DIRECTORY exists!"
file_directory="D"
# last char must be slash
if [[ "$from_path" != */ ]]; then
from_path="${from_path}/"
fi
#src_directory_name = $from_path
else
echo "the source FILE exists!"
file_directory="F"
#src_directory_name = "$(dirname "${from_path}")"
#src_file_name = "$(basename "${from_path}")"
fi
else
echo "ERROR - Source File or directory does not exist... $line ... SKIPPED" | tee -a "${LOG_FILE}"
continue
fi
# echo "FROM_PATH: $from_path - TO:PATH: $to_path - compression: $compression - avoid_delete: $avoid_delete"
#Destination Path checks: only directory accepped
if [[ "$to_path" != */ ]]; then
to_path="${to_path}/"
fi
if [ -d "$to_path" ]; then
echo "the destination DIRECTORY exists!"
else
mkdir -p "$to_path"
echo "the destination DIRECTORY : $to_path created"
fi
# Backup
if [[ "$compression" == none ]]; then
# no compression
opts=" "
if [[ "$avoid_delete" != "true" ]]; then
opts=" --delete "
fi
echo rsync -s -avzPth $opts "$from_path" "$to_path"
rsync -avzPth -s $opts "$from_path" "$to_path" | tee -a "${LOG_FILE}"
else
# compression
# parent directory
src_parent_folder="$(dirname "${from_path}")"
# last folder or file
src_name="$(basename "${from_path}")"
#using same name of source file or last directory name
zip_filename="${src_name}.zip"
pushd ./
cd "$src_parent_folder"
echo zip -r "$to_path""$zip_filename" ./$src_name
zip -r "$to_path""$zip_filename" ./$src_name | tee -a "${LOG_FILE}"
popd
fi
done < "$CONFIG_FILE_PATH"
echo "Buckup done at `date`" | tee -a "${LOG_FILE}"
popd