Subversion Repositories oZimbraBackup

Rev

Rev 2 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 2 Rev 3
1
#!/bin/bash
1
#!/bin/bash
2
 
2
 
-
 
3
#
3
# This script will do various backups of Zimbra depending on which you choose,
4
# This script will do various backups of Zimbra depending on which you choose,
4
# most of them are cold backups except the msg backup which hot copies the 'store'
5
# most of them are cold backups except the msg backup which hot copies the 'store'
5
# folder for possible individual mail retrieval. Be sure to change the variables below
6
# folder for possible individual mail retrieval. Be sure to change the variables below
6
# to point to where you got the Zimbra folder and where you want it to be backed up to.
7
# to point to where you got the Zimbra folder and where you want it to be backed up to.
7
#
8
#
8
# This script must be run as root or a user with equal privileges or it will not work.
9
# This script must be run as root or a user with equal privileges or it will not work.
9
#
10
#
10
# When you run this script via crontab be sure to add '> /dev/null 2>&1' at the end
11
# When you run this script via crontab be sure to add '> /dev/null 2>&1' at the end
11
# of the script like below or the tar command will fail for no apparent reason.
12
# of the script like below or the tar command will fail for no apparent reason.
12
# 00 12 * * * oZimbraBackup.sh --full > /dev/null 2>&1
13
# 00 12 * * * oZimbraBackup.sh --full > /dev/null 2>&1
13
#
14
#
14
# As of 2008-04-16 this script uses some extra software to extend this script,
15
# As of 2008-04-16 this script uses some extra software to extend this script,
15
# the scripts standard function will still function without these extra software's but if you
16
# the scripts standard function will still function without these extra software's but if you
16
# intend to use this scripts built in file transfer functions you must install the described software below.
17
# intend to use this scripts built in file transfer functions you must install the described software below.
17
#
18
#
18
# Required software: rsync for normal operation and ftp or scp & expect for file transfer capabillities.
19
# Required software: rsync for normal operation and ftp or scp & expect for file transfer capabillities.
19
#
20
#
20
# Bits and pieces was adopted from a script created by Daniel W. Martin, 9 Sept 2007
21
# Bits and pieces was adopted from a script created by Daniel W. Martin, 9 Sept 2007
21
# Licensed under BSDL license, see license.txt for information.
22
# Licensed under BSDL license, see license.txt for information.
22
#
23
#
23
# Developer: oSource Development(as of 2009-07-01)
24
# Developer: oSource Development(as of 2009-07-01)
24
# DevTeam: Marcus Uddenhed
25
# DevTeam: Marcus Uddenhed
25
# Version: 1.0.5
26
# Version: 1.0.6
26
# Last updated: 2012-01-02 23:15
27
# Updated: 2014-05-18 16:00
-
 
28
#
27
 
29
 
28
#### Global Settings ####
30
#### Global Settings ####
29
ZimInstPath=/opt			# Installation path for Zimbra, excluding the Zimbra folder.
31
ZimInstPath=/opt			# Installation path for Zimbra, excluding the Zimbra folder.
30
ZimHome=zimbra				# The Zimbra installation folder, excluding path to folder.
32
ZimHome=zimbra				# The Zimbra installation folder, excluding path to folder.
31
ZimBackupPath=/opt/backup		# Root folder for backup where backup files will be placed.
33
ZimBackupPath=/opt/backup		# Root folder for backup where backup files will be placed.
32
 
34
 
33
#### Log Settings ####
35
#### Log Settings ####
34
ZimLogEnable=yes			# Turns logging on or off(yes/no).
36
ZimLogEnable=yes			# Turns logging on or off(yes/no).
35
ZimLogLogRotate=no			# Enables log rotating(yes/no)
37
ZimLogLogRotate=no			# Enables log rotating(yes/no)
36
ZimLogRotateInt=day			# How often should we rotate logs(day, week or month)
38
ZimLogRotateInt=day			# How often should we rotate logs(day, week or month)
37
ZimLogPath=/opt/logs			# Folder for log files
39
ZimLogPath=/opt/logs			# Folder for log files
38
ZimLogVerbose=no			# Activates extra logging information(yes/no)
40
ZimLogVerbose=no			# Activates extra logging information(yes/no)
39
 
41
 
40
#### File Transfer Settings ####
42
#### File Transfer Settings ####
41
 
43
 
42
# Enable Services (yes/no)
44
# Enable Services (yes/no)
43
ZimFtpEnable=no				# Enable/Disable ftp file transfer(yes/no)
45
ZimFtpEnable=no				# Enable/Disable ftp file transfer(yes/no)
44
ZimScpEnable=no				# Enable/Disable scp file transfer(yes/no)
46
ZimScpEnable=no				# Enable/Disable scp file transfer(yes/no)
45
 
47
 
46
# Extra FTP Settings
48
# Extra FTP Settings
47
ZimFtpOpt=''				# Extra options for ftp file transfer, see manual for ftp command
49
ZimFtpOpt=''				# Extra options for ftp file transfer, see manual for ftp command
48
 
50
 
49
# Extra SCP Settings
51
# Extra SCP Settings
50
ZimScpOpt=''				# Extra options for scp file transfer, see manual for scp command
52
ZimScpOpt=''				# Extra options for scp file transfer, see manual for scp command
51
 
53
 
52
# Common Settings
54
# Common Settings
53
ZimFilehostUser=			# Username for file transfers
55
ZimFilehostUser=			# Username for file transfers
54
ZimFilehostPass=			# Password for file transfers
56
ZimFilehostPass=			# Password for file transfers
55
ZimFilehostAddress=			# Host address for file transfers
57
ZimFilehostAddress=			# Host address for file transfers
56
ZimFilehostFolder=			# Folder on host where files will be placed during file transfer
58
ZimFilehostFolder=			# Folder on host where files will be placed during file transfer
57
 
59
 
58
#### File Delete Settings ####
60
#### File Delete Settings ####
59
ZimDeleteLocalFile=no			# Enable/Disable compressed backup file deletion after successful backup(yes/no)
61
ZimDeleteLocalFile=no			# Enable/Disable compressed backup file deletion after successful backup(yes/no)
60
ZimDeleteTimeSet=0			# Set in minutes above 0 to keep a desired amount of files locally,
62
ZimDeleteTimeSet=0			# Set in minutes above 0 to keep a desired amount of files locally,
61
					# be sure to match the time with your backup schedules.
63
					# be sure to match the time with your backup schedules.
62
 
64
 
63
##### Do not change anything below this line unless you know what you are doing #####
65
##### Do not change anything below this line unless you know what you are doing #####
64
 
66
 
65
# Fetch backup type
67
# Fetch backup type
66
ZimBackupType=$1
68
ZimBackupType=$1
67
 
69
 
68
pre_check() {
70
pre_check() {
69
# Set default abort value
71
# Set default abort value
70
ZimAbort=0
72
ZimAbort=0
71
 
73
 
72
# Check for rsync
74
# Check for rsync
73
if [ ! -e /usr/bin/rsync ]
75
if [ ! -e /usr/bin/rsync ]
74
 then
76
 then
75
  echo "Cannot find rsync software..."
77
  echo "Cannot find rsync software..."
76
  ZimAbort=1
78
  ZimAbort=1
77
fi
79
fi
78
 
80
 
79
# Check for tar
81
# Check for tar
80
if [ ! -e /bin/tar ]
82
if [ ! -e /bin/tar ]
81
 then
83
 then
82
  echo "Cannot find tar software..."
84
  echo "Cannot find tar software..."
83
  ZimAbort=1
85
  ZimAbort=1
84
fi
86
fi
85
 
87
 
86
# Check for gzip
88
# Check for gzip
87
if [ ! -e /bin/gzip ]
89
if [ ! -e /bin/gzip ]
88
 then
90
 then
89
  if [ ! -e /usr/bin/gzip ]
91
  if [ ! -e /usr/bin/gzip ]
90
   then
92
   then
91
    echo "Cannot find gzip software..."
93
    echo "Cannot find gzip software..."
92
    ZimAbort=1
94
    ZimAbort=1
93
  fi
95
  fi
94
fi
96
fi
95
 
97
 
96
# Check if expect, ftp & scp is installed when file transfer is set to yes
98
# Check if expect, ftp & scp is installed when file transfer is set to yes
97
if [ $ZimFtpEnable = 'yes' ] || [ $ZimScpEnable = 'yes' ]
99
if [ $ZimFtpEnable = 'yes' ] || [ $ZimScpEnable = 'yes' ]
98
then
100
then
99
 if [ ! -e /usr/bin/expect ]
101
 if [ ! -e /usr/bin/expect ]
100
  then
102
  then
101
   echo "cannot find expect command..."
103
   echo "cannot find expect command..."
102
   ZimAbort=1
104
   ZimAbort=1
103
 fi
105
 fi
104
 if [ $ZimFtpEnable = 'yes' ]
106
 if [ $ZimFtpEnable = 'yes' ]
105
 then
107
 then
106
  if [ ! -e /usr/bin/ftp ]
108
  if [ ! -e /usr/bin/ftp ]
107
   then
109
   then
108
    echo "Cannot find ftp command..."
110
    echo "Cannot find ftp command..."
109
    ZimAbort=1
111
    ZimAbort=1
110
  fi
112
  fi
111
 fi
113
 fi
112
 
114
 
113
 if [ $ZimScpEnable = 'yes' ]
115
 if [ $ZimScpEnable = 'yes' ]
114
 then
116
 then
115
  if [ ! -e /usr/bin/scp ]
117
  if [ ! -e /usr/bin/scp ]
116
   then
118
   then
117
    echo "Cannot find scp command..."
119
    echo "Cannot find scp command..."
118
    ZimAbort=1
120
    ZimAbort=1
119
  fi
121
  fi
120
 fi
122
 fi
121
fi
123
fi
122
 
124
 
123
if [ $ZimAbort = '1' ]
125
if [ $ZimAbort = '1' ]
124
 then
126
 then
125
  echo "Please install above software, script exiting..."
127
  echo "Please install above software, script exiting..."
126
  exit
128
  exit
127
fi
129
fi
128
}
130
}
129
 
131
 
130
pre_load() {
132
pre_load() {
131
# Get temporary folder layout
133
# Get temporary folder layout
132
temp_folders
134
temp_folders
133
 
135
 
134
# Get backup file format
136
# Get backup file format
135
backup_file
137
backup_file
136
 
138
 
137
# Get log file format
139
# Get log file format
138
log_file
140
log_file
139
 
141
 
140
# Check to see if the backup folder exist, create if not
142
# Check to see if the backup folder exist, create if not
141
mkdir -p $ZimBackupPath
143
mkdir -p $ZimBackupPath
142
 
144
 
143
# Check which zimbra version that is installed, for recovery purposes
145
# Check which zimbra version that is installed, for recovery purposes
144
sudo -u zimbra $ZimInstPath/$ZimHome/bin/zmcontrol -v > $ZimBackupPath/zimbra_version.txt
146
sudo -u zimbra $ZimInstPath/$ZimHome/bin/zmcontrol -v > $ZimBackupPath/zimbra_version.txt
145
}
147
}
146
 
148
 
147
full_backup() {
149
full_backup() {
148
if [ $ZimLogEnable = 'yes' ] && [ $ZimLogVerbose = 'yes' ]
150
if [ $ZimLogEnable = 'yes' ] && [ $ZimLogVerbose = 'yes' ]
149
 then
151
 then
150
 
152
 
151
   # Hot sync before shutdown on zimbra folder
153
   # Hot sync before shutdown on zimbra folder
152
   echo "`date "+%Y-%m-%d %H:%M:%S"` - Hot syncing to backup folder..." >> $ZimLogFile
154
   echo "`date "+%Y-%m-%d %H:%M:%S"` - Hot syncing to backup folder..." >> $ZimLogFile
153
   rsync -avHK --delete $ZimInstPath/$ZimHome $ZimFullTmpPath >> $ZimLogFile
155
   rsync -avHK --delete $ZimInstPath/$ZimHome $ZimFullTmpPath >> $ZimLogFile
154
   echo "`date "+%Y-%m-%d %H:%M:%S"` - Hot syncing to backup folder done." >> $ZimLogFile
156
   echo "`date "+%Y-%m-%d %H:%M:%S"` - Hot syncing to backup folder done." >> $ZimLogFile
155
 
157
 
156
   # Stopping Zimbra
158
   # Stopping Zimbra
157
   zimbra_stop
159
   zimbra_stop
158
 
160
 
159
   # Cold sync of zimbra folder
161
   # Cold sync of zimbra folder
160
   echo "`date "+%Y-%m-%d %H:%M:%S"` - Cold syncing to backup folder..." >> $ZimLogFile
162
   echo "`date "+%Y-%m-%d %H:%M:%S"` - Cold syncing to backup folder..." >> $ZimLogFile
161
   rsync -avHK --delete $ZimInstPath/$ZimHome $ZimFullTmpPath >> $ZimLogFile
163
   rsync -avHK --delete $ZimInstPath/$ZimHome $ZimFullTmpPath >> $ZimLogFile
162
   echo "`date "+%Y-%m-%d %H:%M:%S"` - Cold syncing to backup folder done." >> $ZimLogFile
164
   echo "`date "+%Y-%m-%d %H:%M:%S"` - Cold syncing to backup folder done." >> $ZimLogFile
163
 
165
 
164
   # Starting Zimbra
166
   # Starting Zimbra
165
   zimbra_start 
167
   zimbra_start 
166
 
168
 
167
   # Compressing backup for space reduction
169
   # Compressing backup for space reduction
168
   echo "`date "+%Y-%m-%d %H:%M:%S"` - Compressing backup folder..." >> $ZimLogFile
170
   echo "`date "+%Y-%m-%d %H:%M:%S"` - Compressing backup folder..." >> $ZimLogFile
169
   tar -zcvpf $ZimBackupPath/$ZimBackupFile -C $ZimBackupPath tf zimbra_version.txt >> $ZimLogFile
171
   tar -zcvpf $ZimBackupPath/$ZimBackupFile -C $ZimBackupPath tf zimbra_version.txt >> $ZimLogFile
170
   echo "`date "+%Y-%m-%d %H:%M:%S"` - Compressed backup folder." >> $ZimLogFile
172
   echo "`date "+%Y-%m-%d %H:%M:%S"` - Compressed backup folder." >> $ZimLogFile
171
 
173
 
172
   # Cleaning differential folder.
174
   # Cleaning differential folder.
173
   echo "`date "+%Y-%m-%d %H:%M:%S"` - Cleaning differential backup folder..."
175
   echo "`date "+%Y-%m-%d %H:%M:%S"` - Cleaning differential backup folder..."
174
   rm -r -f $ZimDiffTmpPath/* >> $ZimLogFile
176
   rm -r -f $ZimDiffTmpPath/* >> $ZimLogFile
175
   echo "`date "+%Y-%m-%d %H:%M:%S"` - Cleaned differential backup folder."
177
   echo "`date "+%Y-%m-%d %H:%M:%S"` - Cleaned differential backup folder."
176
   
178
   
177
 else
179
 else
178
 
180
 
179
  # Hot sync before shutdown on zimbra folder
181
  # Hot sync before shutdown on zimbra folder
180
  rsync -avHK --delete $ZimInstPath/$ZimHome $ZimFullTmpPath
182
  rsync -avHK --delete $ZimInstPath/$ZimHome $ZimFullTmpPath
181
 
183
 
182
  # Stopping Zimbra
184
  # Stopping Zimbra
183
  zimbra_stop
185
  zimbra_stop
184
 
186
 
185
  # Cold sync of zimbra folder
187
  # Cold sync of zimbra folder
186
  rsync -avHK --delete $ZimInstPath/$ZimHome $ZimFullTmpPath
188
  rsync -avHK --delete $ZimInstPath/$ZimHome $ZimFullTmpPath
187
 
189
 
188
  # Starting Zimbra
190
  # Starting Zimbra
189
  zimbra_start
191
  zimbra_start
190
 
192
 
191
  # Compressing backup for space reduction
193
  # Compressing backup for space reduction
192
  tar -zcvpf $ZimBackupPath/$ZimBackupFile -C $ZimBackupPath tf zimbra_version.txt
194
  tar -zcvpf $ZimBackupPath/$ZimBackupFile -C $ZimBackupPath tf zimbra_version.txt
193
  
195
  
194
  # Cleaning differential folder.
196
  # Cleaning differential folder.
195
   rm -r -f $ZimDiffTmpPath/*
197
   rm -r -f $ZimDiffTmpPath/*
196
fi
198
fi
197
}
199
}
198
 
200
 
199
diff_backup() {
201
diff_backup() {
200
if [ $ZimLogEnable = 'yes' ] && [ $ZimLogVerbose = 'yes' ]
202
if [ $ZimLogEnable = 'yes' ] && [ $ZimLogVerbose = 'yes' ]
201
 then
203
 then
202
  # Cleaning backup folder
204
  # Cleaning backup folder
203
  #echo "`date "+%Y-%m-%d %H:%M:%S"` - Cleaning backup folder..." >> $ZimLogFile
205
  #echo "`date "+%Y-%m-%d %H:%M:%S"` - Cleaning backup folder..." >> $ZimLogFile
204
  #rm -r -f $ZimDiffTmpPath/* >> $ZimLogFile
206
  #rm -r -f $ZimDiffTmpPath/* >> $ZimLogFile
205
  #echo "`date "+%Y-%m-%d %H:%M:%S"` - Cleaning backup folder done." >> $ZimLogFile
207
  #echo "`date "+%Y-%m-%d %H:%M:%S"` - Cleaning backup folder done." >> $ZimLogFile
206
 
208
 
207
  # Hot syncing to backup folder
209
  # Hot syncing to backup folder
208
  echo "`date "+%Y-%m-%d %H:%M:%S"` - Hot syncing to backup folder..." >> $ZimLogFile
210
  echo "`date "+%Y-%m-%d %H:%M:%S"` - Hot syncing to backup folder..." >> $ZimLogFile
209
  rsync -avHK --compare-dest=$ZimFullTmpPath/ $ZimInstPath/$ZimHome $ZimDiffTmpPath >> $ZimLogFile
211
  rsync -avHK --compare-dest=$ZimFullTmpPath/ $ZimInstPath/$ZimHome $ZimDiffTmpPath >> $ZimLogFile
210
  echo "`date "+%Y-%m-%d %H:%M:%S"` - Hot syncing to backup folder done." >> $ZimLogFile
212
  echo "`date "+%Y-%m-%d %H:%M:%S"` - Hot syncing to backup folder done." >> $ZimLogFile
211
 
213
 
212
  # Stopping Zimbra
214
  # Stopping Zimbra
213
  zimbra_stop
215
  zimbra_stop
214
 
216
 
215
  # Cold syncing to backup folder
217
  # Cold syncing to backup folder
216
  echo "`date "+%Y-%m-%d %H:%M:%S"` - Cold syncing to backup folder..." >> $ZimLogFile
218
  echo "`date "+%Y-%m-%d %H:%M:%S"` - Cold syncing to backup folder..." >> $ZimLogFile
217
  rsync -avHK --compare-dest=$ZimFullTmpPath/ $ZimInstPath/$ZimHome $ZimDiffTmpPath >> $ZimLogFile
219
  rsync -avHK --compare-dest=$ZimFullTmpPath/ $ZimInstPath/$ZimHome $ZimDiffTmpPath >> $ZimLogFile
218
  echo "`date "+%Y-%m-%d %H:%M:%S"` - Cold syncing to backup folder done." >> $ZimLogFile
220
  echo "`date "+%Y-%m-%d %H:%M:%S"` - Cold syncing to backup folder done." >> $ZimLogFile
219
 
221
 
220
  # Starting Zimbra
222
  # Starting Zimbra
221
  zimbra_start
223
  zimbra_start
222
 
224
 
223
  # Syncing backup folders
225
  # Syncing backup folders
224
  #echo "`date "+%Y-%m-%d %H:%M:%S"` - Syncing backup folders..." >> $ZimLogFile
226
  #echo "`date "+%Y-%m-%d %H:%M:%S"` - Syncing backup folders..." >> $ZimLogFile
225
  #cp -R $ZimDiffTmpPath/* $ZimFullTmpPath/ >> $ZimLogFile
227
  #cp -R $ZimDiffTmpPath/* $ZimFullTmpPath/ >> $ZimLogFile
226
  #echo "`date "+%Y-%m-%d %H:%M:%S"` - Syncing backup folders done." >> $ZimLogFile
228
  #echo "`date "+%Y-%m-%d %H:%M:%S"` - Syncing backup folders done." >> $ZimLogFile
227
 
229
 
228
  # Compressing backup folder
230
  # Compressing backup folder
229
  echo "`date "+%Y-%m-%d %H:%M:%S"` - Compressing backup folder..." >> $ZimLogFile
231
  echo "`date "+%Y-%m-%d %H:%M:%S"` - Compressing backup folder..." >> $ZimLogFile
230
  tar -zcvpf $ZimBackupPath/$ZimBackupFile -C $ZimBackupPath td zimbra_version.txt >> $ZimLogFile
232
  tar -zcvpf $ZimBackupPath/$ZimBackupFile -C $ZimBackupPath td zimbra_version.txt >> $ZimLogFile
231
  echo "`date "+%Y-%m-%d %H:%M:%S"` - Compressing backup folder done." >> $ZimLogFile
233
  echo "`date "+%Y-%m-%d %H:%M:%S"` - Compressing backup folder done." >> $ZimLogFile
232
 
234
 
233
 else
235
 else
234
 
236
 
235
  # Hot sync before shutdown on zimbra folder
237
  # Hot sync before shutdown on zimbra folder
236
  #rm -R $ZimDiffTmpPath/*
238
  #rm -R $ZimDiffTmpPath/*
237
  rsync -avHK --compare-dest=$ZimFullTmpPath/ $ZimInstPath/$ZimHome $ZimDiffTmpPath
239
  rsync -avHK --compare-dest=$ZimFullTmpPath/ $ZimInstPath/$ZimHome $ZimDiffTmpPath
238
 
240
 
239
  # Stopping Zimbra
241
  # Stopping Zimbra
240
  zimbra_stop
242
  zimbra_stop
241
 
243
 
242
  # Cold sync of zimbra folder
244
  # Cold sync of zimbra folder
243
  rsync -avHK --compare-dest=$ZimFullTmpPath/ $ZimInstPath/$ZimHome $ZimDiffTmpPath
245
  rsync -avHK --compare-dest=$ZimFullTmpPath/ $ZimInstPath/$ZimHome $ZimDiffTmpPath
244
 
246
 
245
  # Starting Zimbra
247
  # Starting Zimbra
246
  zimbra_start
248
  zimbra_start
247
 
249
 
248
  # Syncing files from diff to full backup folder
250
  # Syncing files from diff to full backup folder
249
  #cp -R $ZimDiffTmpPath/* $ZimFullTmpPath/
251
  #cp -R $ZimDiffTmpPath/* $ZimFullTmpPath/
250
 
252
 
251
  # Compressing backup for space reduction
253
  # Compressing backup for space reduction
252
  tar -zcvpf $ZimBackupPath/$ZimBackupFile -C $ZimBackupPath td zimbra_version.txt
254
  tar -zcvpf $ZimBackupPath/$ZimBackupFile -C $ZimBackupPath td zimbra_version.txt
253
fi
255
fi
254
}
256
}
255
 
257
 
256
msgfull_backup() {
258
msgfull_backup() {
257
if [ $ZimLogEnable = 'yes' ] && [ $ZimLogVerbose = 'yes' ]
259
if [ $ZimLogEnable = 'yes' ] && [ $ZimLogVerbose = 'yes' ]
258
 then
260
 then
259
  # Hot syncing to backup folder
261
  # Hot syncing to backup folder
260
  echo "`date "+%Y-%m-%d %H:%M:%S"` - Hot syncing to backup folder..." >> $ZimLogFile
262
  echo "`date "+%Y-%m-%d %H:%M:%S"` - Hot syncing to backup folder..." >> $ZimLogFile
261
  rsync -avHK --delete $ZimInstPath/$ZimHome/store $ZimMsgFullTmpPath >> $ZimLogFile
263
  rsync -avHK --delete $ZimInstPath/$ZimHome/store $ZimMsgFullTmpPath >> $ZimLogFile
262
  echo "`date "+%Y-%m-%d %H:%M:%S"` - Hot syncing to backup folder done." >> $ZimLogFile
264
  echo "`date "+%Y-%m-%d %H:%M:%S"` - Hot syncing to backup folder done." >> $ZimLogFile
263
 
265
 
264
  # Compressing backup folder
266
  # Compressing backup folder
265
  echo "`date "+%Y-%m-%d %H:%M:%S"` - Compressing backup folder..." >> $ZimLogFile
267
  echo "`date "+%Y-%m-%d %H:%M:%S"` - Compressing backup folder..." >> $ZimLogFile
266
  tar -zcvpf $ZimBackupPath/$ZimBackupFile -C $ZimBackupPath tmf zimbra_version.txt >> $ZimLogFile
268
  tar -zcvpf $ZimBackupPath/$ZimBackupFile -C $ZimBackupPath tmf zimbra_version.txt >> $ZimLogFile
267
  echo "`date "+%Y-%m-%d %H:%M:%S"` - Compressing backup folder done." >> $ZimLogFile
269
  echo "`date "+%Y-%m-%d %H:%M:%S"` - Compressing backup folder done." >> $ZimLogFile
268
  
270
  
269
  echo "`date "+%Y-%m-%d %H:%M:%S"` - Cleaning differential backup folder..."
271
  echo "`date "+%Y-%m-%d %H:%M:%S"` - Cleaning differential backup folder..."
270
  rm -r -f $ZimMsgDiffTmpPath/* >> $ZimLogFile
272
  rm -r -f $ZimMsgDiffTmpPath/* >> $ZimLogFile
271
  echo "`date "+%Y-%m-%d %H:%M:%S"` - Cleaned differential backup folder."
273
  echo "`date "+%Y-%m-%d %H:%M:%S"` - Cleaned differential backup folder."
272
 
274
 
273
 else
275
 else
274
  # Hot syncing to backup folder
276
  # Hot syncing to backup folder
275
  rsync -avHK --delete $ZimInstPath/$ZimHome/store $ZimMsgFullTmpPath
277
  rsync -avHK --delete $ZimInstPath/$ZimHome/store $ZimMsgFullTmpPath
276
 
278
 
277
  # Compressing backup folder
279
  # Compressing backup folder
278
  tar -zcvpf $ZimBackupPath/$ZimBackupFile -C $ZimBackupPath tmf zimbra_version.txt
280
  tar -zcvpf $ZimBackupPath/$ZimBackupFile -C $ZimBackupPath tmf zimbra_version.txt
279
  
281
  
280
  # Cleaning differential folder
282
  # Cleaning differential folder
281
  rm -r -f $ZimMsgDiffTmpPath/*
283
  rm -r -f $ZimMsgDiffTmpPath/*
282
fi
284
fi
283
}
285
}
284
 
286
 
285
msgdiff_backup() {
287
msgdiff_backup() {
286
if [ $ZimLogEnable = 'yes' ] && [ $ZimLogVerbose = 'yes' ]
288
if [ $ZimLogEnable = 'yes' ] && [ $ZimLogVerbose = 'yes' ]
287
 then
289
 then
288
  # Cleaning backup folder
290
  # Cleaning backup folder
289
  #echo "`date "+%Y-%m-%d %H:%M:%S"` - Cleaning backup folder..." >> $ZimLogFile
291
  #echo "`date "+%Y-%m-%d %H:%M:%S"` - Cleaning backup folder..." >> $ZimLogFile
290
  #rm -r -f $ZimMsgDiffTmpPath/* >> $ZimLogFile
292
  #rm -r -f $ZimMsgDiffTmpPath/* >> $ZimLogFile
291
  #echo "`date "+%Y-%m-%d %H:%M:%S"` - Cleaning backup folder done." >> $ZimLogFile
293
  #echo "`date "+%Y-%m-%d %H:%M:%S"` - Cleaning backup folder done." >> $ZimLogFile
292
 
294
 
293
  # Hot syncing to backup folder
295
  # Hot syncing to backup folder
294
  echo "`date "+%Y-%m-%d %H:%M:%S"` - Hot syncing to backup folder..." >> $ZimLogFile
296
  echo "`date "+%Y-%m-%d %H:%M:%S"` - Hot syncing to backup folder..." >> $ZimLogFile
295
  rsync -avHK --compare-dest=$ZimMsgFullTmpPath/ $ZimInstPath/$ZimHome/store $ZimMsgDiffTmpPath >> $ZimLogFile
297
  rsync -avHK --compare-dest=$ZimMsgFullTmpPath/ $ZimInstPath/$ZimHome/store $ZimMsgDiffTmpPath >> $ZimLogFile
296
  echo "`date "+%Y-%m-%d %H:%M:%S"` - Hot syncing to backup folder done." >> $ZimLogFile
298
  echo "`date "+%Y-%m-%d %H:%M:%S"` - Hot syncing to backup folder done." >> $ZimLogFile
297
 
299
 
298
  # Compressing backup folder
300
  # Compressing backup folder
299
  echo "`date "+%Y-%m-%d %H:%M:%S"` - Compressing backup folder..." >> $ZimLogFile
301
  echo "`date "+%Y-%m-%d %H:%M:%S"` - Compressing backup folder..." >> $ZimLogFile
300
  tar -zcvpf $ZimBackupPath/$ZimBackupFile -C $ZimBackupPath tmd zimbra_version.txt >> $ZimLogFile
302
  tar -zcvpf $ZimBackupPath/$ZimBackupFile -C $ZimBackupPath tmd zimbra_version.txt >> $ZimLogFile
301
  echo "`date "+%Y-%m-%d %H:%M:%S"` - Compressing backup folder done." >> $ZimLogFile
303
  echo "`date "+%Y-%m-%d %H:%M:%S"` - Compressing backup folder done." >> $ZimLogFile
302
 
304
 
303
 else
305
 else
304
  # Cleaning backup folder
306
  # Cleaning backup folder
305
  #rm -r -f $ZimMsgDiffTmpPath/*
307
  #rm -r -f $ZimMsgDiffTmpPath/*
306
 
308
 
307
  # Hot syncing to backup folder
309
  # Hot syncing to backup folder
308
  rsync -avHK --compare-dest=$ZimMsgFullTmpPath/ $ZimInstPath/$ZimHome/store $ZimMsgDiffTmpPath
310
  rsync -avHK --compare-dest=$ZimMsgFullTmpPath/ $ZimInstPath/$ZimHome/store $ZimMsgDiffTmpPath
309
 
311
 
310
  # Compressing backup folder
312
  # Compressing backup folder
311
  tar -zcvpf $ZimBackupPath/$ZimBackupFile -C $ZimBackupPath tmd zimbra_version.txt
313
  tar -zcvpf $ZimBackupPath/$ZimBackupFile -C $ZimBackupPath tmd zimbra_version.txt
312
fi
314
fi
313
}
315
}
314
 
316
 
315
file_transfer() {
317
file_transfer() {
316
# Transfer with ftp
318
# Transfer with ftp
317
if [ $ZimFtpEnable == "yes" ]
319
if [ $ZimFtpEnable == "yes" ]
318
then
320
then
-
 
321
if [ "$2" = "--no-send" ]
-
 
322
then
-
 
323
  # If --no-send is set ignore sending file to off site.
-
 
324
  echo "`date "+%Y-%m-%d %H:%M:%S"` - Backup not sending backup file to external storage, --no-send is set." >> $ZimLogFile
-
 
325
  echo "Not sending backup to external storage, --no-send is set."
-
 
326
else
319
if [ $ZimLogEnable = 'yes' ] && [ $ZimLogVerbose = 'yes' ]
327
if [ $ZimLogEnable = 'yes' ] && [ $ZimLogVerbose = 'yes' ]
320
 then
328
 then
321
  # Send task start time to log
329
  # Send task start time to log
322
  echo "`date "+%Y-%m-%d %H:%M:%S"` - Sending file via ftp to off-site storage..." >> $ZimLogFile
330
  echo "`date "+%Y-%m-%d %H:%M:%S"` - Sending file via ftp to off-site storage..." >> $ZimLogFile
323
 
331
 
324
  # Make a temporary script for expect commands
332
  # Make a temporary script for expect commands
325
  touch $ZimBackupPath/ftp.exp
333
  touch $ZimBackupPath/ftp.exp
326
 
334
 
327
  # Fill script with commands
335
  # Fill script with commands
328
  echo '#!/usr/bin/expect --' >> $ZimBackupPath/ftp.exp
336
  echo '#!/usr/bin/expect --' >> $ZimBackupPath/ftp.exp
329
  echo 'set timeout -1' >> $ZimBackupPath/ftp.exp
337
  echo 'set timeout -1' >> $ZimBackupPath/ftp.exp
330
  echo 'spawn ftp '$ZimFilehostAddress >> $ZimBackupPath/ftp.exp
338
  echo 'spawn ftp '$ZimFilehostAddress >> $ZimBackupPath/ftp.exp
331
  echo 'expect ):' >> $ZimBackupPath/ftp.exp
339
  echo 'expect ):' >> $ZimBackupPath/ftp.exp
332
  echo 'send '$ZimFilehostUser'\r' >> $ZimBackupPath/ftp.exp
340
  echo 'send '$ZimFilehostUser'\r' >> $ZimBackupPath/ftp.exp
333
  echo 'expect :' >> $ZimBackupPath/ftp.exp
341
  echo 'expect :' >> $ZimBackupPath/ftp.exp
334
  echo 'send '$ZimFilehostPass'\r' >> $ZimBackupPath/ftp.exp
342
  echo 'send '$ZimFilehostPass'\r' >> $ZimBackupPath/ftp.exp
335
  echo 'expect >' >> $ZimBackupPath/ftp.exp
343
  echo 'expect >' >> $ZimBackupPath/ftp.exp
336
  echo 'send '$ZimFtpOpt'\r' >> $ZimBackupPath/ftp.exp
344
  echo 'send '$ZimFtpOpt'\r' >> $ZimBackupPath/ftp.exp
337
  echo 'send "send '$ZimBackupPath/$ZimBackupFile $ZimFilehostFolder/$ZimBackupFile'\r"' >> $ZimBackupPath/ftp.exp
345
  echo 'send "send '$ZimBackupPath/$ZimBackupFile $ZimFilehostFolder/$ZimBackupFile'\r"' >> $ZimBackupPath/ftp.exp
338
  echo 'expect >' >> $ZimBackupPath/ftp.exp
346
  echo 'expect >' >> $ZimBackupPath/ftp.exp
339
  echo 'send quit\r' >> $ZimBackupPath/ftp.exp
347
  echo 'send quit\r' >> $ZimBackupPath/ftp.exp
340
  echo 'expect closed' >> $ZimBackupPath/ftp.exp
348
  echo 'expect closed' >> $ZimBackupPath/ftp.exp
341
 
349
 
342
  # Run expect with created script
350
  # Run expect with created script
343
  expect $ZimBackupPath/ftp.exp >> $ZimLogFile
351
  expect $ZimBackupPath/ftp.exp >> $ZimLogFile
344
 
352
 
345
  # Delete temporary expect script
353
  # Delete temporary expect script
346
  rm $ZimBackupPath/ftp.exp
354
  rm $ZimBackupPath/ftp.exp
347
 
355
 
348
  # Send task stop time to log
356
  # Send task stop time to log
349
  echo "`date "+%Y-%m-%d %H:%M:%S"` - Sending file via ftp to off-site storage done." >> $ZimLogFile
357
  echo "`date "+%Y-%m-%d %H:%M:%S"` - Sending file via ftp to off-site storage done." >> $ZimLogFile
350
 
358
 
351
 else
359
 else
352
 
360
 
353
  # Send task start time to log
361
  # Send task start time to log
354
  echo "`date "+%Y-%m-%d %H:%M:%S"` - Sending file via ftp to off-site storage..." >> $ZimLogFile
362
  echo "`date "+%Y-%m-%d %H:%M:%S"` - Sending file via ftp to off-site storage..." >> $ZimLogFile
355
 
363
 
356
  # Make a temporary script for expect commands
364
  # Make a temporary script for expect commands
357
  touch $ZimBackupPath/ftp.exp
365
  touch $ZimBackupPath/ftp.exp
358
 
366
 
359
  # Fill script with commands
367
  # Fill script with commands
360
  echo '#!/usr/bin/expect --' >> $ZimBackupPath/ftp.exp
368
  echo '#!/usr/bin/expect --' >> $ZimBackupPath/ftp.exp
361
  echo 'set timeout -1' >> $ZimBackupPath/ftp.exp
369
  echo 'set timeout -1' >> $ZimBackupPath/ftp.exp
362
  echo 'spawn ftp '$ZimFilehostAddress >> $ZimBackupPath/ftp.exp
370
  echo 'spawn ftp '$ZimFilehostAddress >> $ZimBackupPath/ftp.exp
363
  echo 'expect ):' >> $ZimBackupPath/ftp.exp
371
  echo 'expect ):' >> $ZimBackupPath/ftp.exp
364
  echo 'send '$ZimFilehostUser'\r' >> $ZimBackupPath/ftp.exp
372
  echo 'send '$ZimFilehostUser'\r' >> $ZimBackupPath/ftp.exp
365
  echo 'expect :' >> $ZimBackupPath/ftp.exp
373
  echo 'expect :' >> $ZimBackupPath/ftp.exp
366
  echo 'send '$ZimFilehostPass'\r' >> $ZimBackupPath/ftp.exp
374
  echo 'send '$ZimFilehostPass'\r' >> $ZimBackupPath/ftp.exp
367
  echo 'expect >' >> $ZimBackupPath/ftp.exp
375
  echo 'expect >' >> $ZimBackupPath/ftp.exp
368
  echo 'send '$ZimFtpOpt'\r' >> $ZimBackupPath/ftp.exp
376
  echo 'send '$ZimFtpOpt'\r' >> $ZimBackupPath/ftp.exp
369
  echo 'send "send '$ZimBackupPath/$ZimBackupFile $ZimFilehostFolder/$ZimBackupFile'\r"' >> $ZimBackupPath/ftp.exp
377
  echo 'send "send '$ZimBackupPath/$ZimBackupFile $ZimFilehostFolder/$ZimBackupFile'\r"' >> $ZimBackupPath/ftp.exp
370
  echo 'expect >' >> $ZimBackupPath/ftp.exp
378
  echo 'expect >' >> $ZimBackupPath/ftp.exp
371
  echo 'send quit\r' >> $ZimBackupPath/ftp.exp
379
  echo 'send quit\r' >> $ZimBackupPath/ftp.exp
372
  echo 'expect closed' >> $ZimBackupPath/ftp.exp
380
  echo 'expect closed' >> $ZimBackupPath/ftp.exp
373
 
381
 
374
  # Run expect with created script
382
  # Run expect with created script
375
  expect $ZimBackupPath/ftp.exp
383
  expect $ZimBackupPath/ftp.exp
376
 
384
 
377
  # Delete temporary expect script
385
  # Delete temporary expect script
378
  rm $ZimBackupPath/ftp.exp
386
  rm $ZimBackupPath/ftp.exp
379
 
387
 
380
  # Send task stop time to log
388
  # Send task stop time to log
381
  echo "`date "+%Y-%m-%d %H:%M:%S"` - Sending file via ftp to off-site storage done." >> $ZimLogFile
389
  echo "`date "+%Y-%m-%d %H:%M:%S"` - Sending file via ftp to off-site storage done." >> $ZimLogFile
382
 
390
 
383
 fi
391
 fi
384
fi
392
fi
-
 
393
fi
385
 
394
 
386
# Transfer with scp
395
# Transfer with scp
387
if [ $ZimScpEnable == "yes" ]
396
if [ $ZimScpEnable == "yes" ]
388
then
397
then
-
 
398
if [ "$2" = "--no-send" ]
-
 
399
then
-
 
400
  # If --no-send is set ignore sending file to off site.
-
 
401
  echo "`date "+%Y-%m-%d %H:%M:%S"` - Backup not sending backup file to external storage, --no-send is set." >> $ZimLogFile
-
 
402
  echo "Not sending backup to external storage, --no-send is set."
-
 
403
else
389
 if [ $ZimLogEnable = 'yes' ] && [ $ZimLogVerbose = 'yes' ]
404
 if [ $ZimLogEnable = 'yes' ] && [ $ZimLogVerbose = 'yes' ]
390
  then
405
  then
391
 
406
 
392
  # Send task start time to log
407
  # Send task start time to log
393
   echo "`date "+%Y-%m-%d %H:%M:%S"` - Sending file via scp to off-site storage..." >> $ZimLogFile
408
   echo "`date "+%Y-%m-%d %H:%M:%S"` - Sending file via scp to off-site storage..." >> $ZimLogFile
394
 
409
 
395
   # Make a temporary script for expect commands
410
   # Make a temporary script for expect commands
396
   touch $ZimBackupPath/scp.exp
411
   touch $ZimBackupPath/scp.exp
397
 
412
 
398
   # Fill script with commands
413
   # Fill script with commands
399
   echo '#!/usr/bin/expect --' >> $ZimBackupPath/scp.exp
414
   echo '#!/usr/bin/expect --' >> $ZimBackupPath/scp.exp
400
   echo 'set timeout -1' >> $ZimBackupPath/scp.exp
415
   echo 'set timeout -1' >> $ZimBackupPath/scp.exp
401
   echo 'spawn scp '$ZimScpOpt $ZimBackupPath/$ZimBackupFile $ZimFilehostUser'@'$ZimFilehostAddress':'$ZimFilehostFolder >> $ZimBackupPath/scp.exp
416
   echo 'spawn scp '$ZimScpOpt $ZimBackupPath/$ZimBackupFile $ZimFilehostUser'@'$ZimFilehostAddress':'$ZimFilehostFolder >> $ZimBackupPath/scp.exp
402
   echo 'expect :' >> $ZimBackupPath/scp.exp
417
   echo 'expect :' >> $ZimBackupPath/scp.exp
403
   echo 'send '$ZimFilehostPass'\r' >> $ZimBackupPath/scp.exp
418
   echo 'send '$ZimFilehostPass'\r' >> $ZimBackupPath/scp.exp
404
   echo 'expect closed' >> $ZimBackupPath/scp.exp
419
   echo 'expect closed' >> $ZimBackupPath/scp.exp
405
 
420
 
406
   # Run expect with created script
421
   # Run expect with created script
407
   expect $ZimBackupPath/scp.exp >> $ZimLogFile
422
   expect $ZimBackupPath/scp.exp >> $ZimLogFile
408
 
423
 
409
   # Delete temporary expect script
424
   # Delete temporary expect script
410
   rm $ZimBackupPath/scp.exp
425
   rm $ZimBackupPath/scp.exp
411
 
426
 
412
  # Send task stop time to log
427
  # Send task stop time to log
413
   echo "`date "+%Y-%m-%d %H:%M:%S"` - Sending file via scp to off-site storage done." >> $ZimLogFile
428
   echo "`date "+%Y-%m-%d %H:%M:%S"` - Sending file via scp to off-site storage done." >> $ZimLogFile
414
 
429
 
415
  else
430
  else
416
 
431
 
417
   # Send task start time to log
432
   # Send task start time to log
418
   echo "`date "+%Y-%m-%d %H:%M:%S"` - Sending file via scp to off-site storage..." >> $ZimLogFile
433
   echo "`date "+%Y-%m-%d %H:%M:%S"` - Sending file via scp to off-site storage..." >> $ZimLogFile
419
 
434
 
420
   # Make a temporary script for expect commands
435
   # Make a temporary script for expect commands
421
   touch $ZimBackupPath/scp.exp
436
   touch $ZimBackupPath/scp.exp
422
 
437
 
423
   # Fill script with commands
438
   # Fill script with commands
424
   echo '#!/usr/bin/expect --' >> $ZimBackupPath/scp.exp
439
   echo '#!/usr/bin/expect --' >> $ZimBackupPath/scp.exp
425
   echo 'set timeout -1' >> $ZimBackupPath/scp.exp
440
   echo 'set timeout -1' >> $ZimBackupPath/scp.exp
426
   echo 'spawn scp '$ZimScpOpt $ZimBackupPath/$ZimBackupFile $ZimFilehostUser'@'$ZimFilehostAddress':'$ZimFilehostFolder >> $ZimBackupPath/scp.exp
441
   echo 'spawn scp '$ZimScpOpt $ZimBackupPath/$ZimBackupFile $ZimFilehostUser'@'$ZimFilehostAddress':'$ZimFilehostFolder >> $ZimBackupPath/scp.exp
427
   echo 'expect :' >> $ZimBackupPath/scp.exp
442
   echo 'expect :' >> $ZimBackupPath/scp.exp
428
   echo 'send '$ZimFilehostPass'\r' >> $ZimBackupPath/scp.exp
443
   echo 'send '$ZimFilehostPass'\r' >> $ZimBackupPath/scp.exp
429
   echo 'expect closed' >> $ZimBackupPath/scp.exp
444
   echo 'expect closed' >> $ZimBackupPath/scp.exp
430
 
445
 
431
   # Run expect with created script
446
   # Run expect with created script
432
   expect $ZimBackupPath/scp.exp
447
   expect $ZimBackupPath/scp.exp
433
 
448
 
434
   # Delete temporary expect script
449
   # Delete temporary expect script
435
   rm $ZimBackupPath/scp.exp
450
   rm $ZimBackupPath/scp.exp
436
 
451
 
437
   # Send task stop time to log
452
   # Send task stop time to log
438
   echo "`date "+%Y-%m-%d %H:%M:%S"` - Sending file via scp to off-site storage done." >> $ZimLogFile
453
   echo "`date "+%Y-%m-%d %H:%M:%S"` - Sending file via scp to off-site storage done." >> $ZimLogFile
439
 
454
 
440
 fi
455
 fi
441
fi
456
fi
-
 
457
fi
442
 
458
 
443
# Remove local file(s) if ZimDeleteLocalFile is set to 'yes'
459
# Remove local file(s) if ZimDeleteLocalFile is set to 'yes'
444
if [ $ZimDeleteLocalFile == "yes" ]
460
if [ $ZimDeleteLocalFile == "yes" ]
445
then
461
then
446
 if [ $ZimLogEnable = 'yes' ] && [ $ZimLogVerbose = 'yes' ]
462
 if [ $ZimLogEnable = 'yes' ] && [ $ZimLogVerbose = 'yes' ]
447
  then
463
  then
448
 
464
 
449
  # Send task start time to log
465
  # Send task start time to log
450
   echo "`date "+%Y-%m-%d %H:%M:%S"` - Deleting local file(s)..." >> $ZimLogFile
466
   echo "`date "+%Y-%m-%d %H:%M:%S"` - Deleting local file(s)..." >> $ZimLogFile
451
 
467
 
452
   # Remove backup files matching criteria
468
   # Remove backup files matching criteria
453
   find $ZimBackupPath -maxdepth 1 -type f -mmin +$ZimDeleteTimeSet -name ZimBackup\*.tar.gz -exec rm {} +  >> $ZimLogFile
469
   find $ZimBackupPath -maxdepth 1 -type f -mmin +$ZimDeleteTimeSet -name ZimBackup\*.tar.gz -exec rm {} +  >> $ZimLogFile
454
 
470
 
455
   # Send task stop time to log
471
   # Send task stop time to log
456
   echo "`date "+%Y-%m-%d %H:%M:%S"` - Deleting local file(s) done." >> $ZimLogFile
472
   echo "`date "+%Y-%m-%d %H:%M:%S"` - Deleting local file(s) done." >> $ZimLogFile
457
 
473
 
458
  else
474
  else
459
 
475
 
460
   # Remove backup files matching criteria
476
   # Remove backup files matching criteria
461
   find $ZimBackupPath -maxdepth 1 -type f -mmin +$ZimDeleteTimeSet -name ZimBackup\*.tar.gz -exec rm {} +
477
   find $ZimBackupPath -maxdepth 1 -type f -mmin +$ZimDeleteTimeSet -name ZimBackup\*.tar.gz -exec rm {} +
462
 
478
 
463
 fi
479
 fi
464
fi
480
fi
465
}
481
}
466
 
482
 
467
log_start() {
483
log_start() {
468
if [ $ZimLogEnable = 'yes' ]
484
if [ $ZimLogEnable = 'yes' ]
469
 then
485
 then
470
 
486
 
471
  # Sending backup start time to log
487
  # Sending backup start time to log
472
  echo "" >> $ZimLogFile
488
  echo "" >> $ZimLogFile
473
  echo "-------------------------------------------------------" >> $ZimLogFile
489
  echo "-------------------------------------------------------" >> $ZimLogFile
474
  echo "Backup Started: `date "+%Y-%m-%d %H:%M:%S"` Type: $ZimBackupType" >> $ZimLogFile
490
  echo "Backup Started: `date "+%Y-%m-%d %H:%M:%S"` Type: $ZimBackupType" >> $ZimLogFile
475
 
491
 
476
fi
492
fi
477
}
493
}
478
 
494
 
479
log_end() {
495
log_end() {
480
if [ $ZimLogEnable = 'yes' ]
496
if [ $ZimLogEnable = 'yes' ]
481
 then
497
 then
482
 
498
 
483
  # Sending backup stop time to log
499
  # Sending backup stop time to log
484
  echo "Backup Finished: `date "+%Y-%m-%d %H:%M:%S"` Type: $ZimBackupType" >> $ZimLogFile
500
  echo "Backup Finished: `date "+%Y-%m-%d %H:%M:%S"` Type: $ZimBackupType" >> $ZimLogFile
485
  echo "-------------------------------------------------------" >> $ZimLogFile
501
  echo "-------------------------------------------------------" >> $ZimLogFile
486
 
502
 
487
fi
503
fi
488
}
504
}
489
 
505
 
490
zimbra_start() {
506
zimbra_start() {
491
if [ "$2" = "--no-start" ]
507
if [ "$2" = "--no-start" ]
492
then
508
then
493
  # If --no-start is set ignore starting Zimbra
509
  # If --no-start is set ignore starting Zimbra
494
  echo "`date "+%Y-%m-%d %H:%M:%S"` - Zimbra services not starting, --no-start is set." >> $ZimLogFile
510
  echo "`date "+%Y-%m-%d %H:%M:%S"` - Zimbra services not starting, --no-start is set." >> $ZimLogFile
495
  echo "Zimbra services not starting, --no-start is set."
511
  echo "Zimbra services not starting, --no-start is set."
496
else
512
else
497
 # Starting Zimbra
513
 # Starting Zimbra
498
 if [ $ZimLogEnable = 'yes' ]
514
 if [ $ZimLogEnable = 'yes' ]
499
  then
515
  then
500
   # Sending task start time to log
516
   # Sending task start time to log
501
   echo "`date "+%Y-%m-%d %H:%M:%S"` - Zimbra services starting..." >> $ZimLogFile
517
   echo "`date "+%Y-%m-%d %H:%M:%S"` - Zimbra services starting..." >> $ZimLogFile
502
 
518
 
503
   # Starting Zimbra
519
   # Starting Zimbra
504
   su zimbra -c -l "zmcontrol start" >> $ZimLogFile
520
   su zimbra -c -l "zmcontrol start" >> $ZimLogFile
505
 
521
 
506
   # Send task stop time to log
522
   # Send task stop time to log
507
   echo "`date "+%Y-%m-%d %H:%M:%S"` - Zimbra services started." >> $ZimLogFile
523
   echo "`date "+%Y-%m-%d %H:%M:%S"` - Zimbra services started." >> $ZimLogFile
508
 
524
 
509
  else
525
  else
510
 
526
 
511
   # Starting Zimbra
527
   # Starting Zimbra
512
   su zimbra -c -l "zmcontrol start"
528
   su zimbra -c -l "zmcontrol start"
513
 
529
 
514
  fi
530
  fi
515
fi
531
fi
516
}
532
}
517
 
533
 
518
zimbra_stop() {
534
zimbra_stop() {
519
# Stopping Zimbra
535
# Stopping Zimbra
520
if [ $ZimLogEnable = 'yes' ]
536
if [ $ZimLogEnable = 'yes' ]
521
 then
537
 then
522
 
538
 
523
  # Sending task start time to log
539
  # Sending task start time to log
524
  echo "`date "+%Y-%m-%d %H:%M:%S"` - Zimbra services stopping..." >> $ZimLogFile
540
  echo "`date "+%Y-%m-%d %H:%M:%S"` - Zimbra services stopping..." >> $ZimLogFile
525
 
541
 
526
  # Stopping Zimbra
542
  # Stopping Zimbra
527
  su zimbra -c -l "zmcontrol stop" >> $ZimLogFile
543
  su zimbra -c -l "zmcontrol stop" >> $ZimLogFile
528
 
544
 
529
  # Sending task stop time to log
545
  # Sending task stop time to log
530
  echo "`date "+%Y-%m-%d %H:%M:%S"` - Zimbra services stopped." >> $ZimLogFile
546
  echo "`date "+%Y-%m-%d %H:%M:%S"` - Zimbra services stopped." >> $ZimLogFile
531
 
547
 
532
  # Sleep for 10 seconds to give shutdown some extra time before backup starts
548
  # Sleep for 10 seconds to give shutdown some extra time before backup starts
533
  sleep 10
549
  sleep 10
534
 
550
 
535
else
551
else
536
 
552
 
537
  # Stopping Zimbra
553
  # Stopping Zimbra
538
  su zimbra -c -l "zmcontrol stop"
554
  su zimbra -c -l "zmcontrol stop"
539
 
555
 
540
  # Sleep for 10 seconds to give shutdown some extra time before backup starts
556
  # Sleep for 10 seconds to give shutdown some extra time before backup starts
541
  sleep 10
557
  sleep 10
542
 
558
 
543
fi
559
fi
544
}
560
}
545
 
561
 
546
full_restore() {
562
full_restore() {
547
echo "Full Restore under development"
563
echo "Full Restore under development"
548
}
564
}
549
 
565
 
550
diff_restore() {
566
diff_restore() {
551
echo "Diff Restore under development"
567
echo "Diff Restore under development"
552
}
568
}
553
 
569
 
554
backup_file() {
570
backup_file() {
555
# Checks what backup is choosen and sets file-name appropiate
571
# Checks what backup is choosen and sets file-name appropiate
556
 
572
 
557
# Full system backup
573
# Full system backup
558
if [ "$ZimBackupType" = "--full" ]
574
if [ "$ZimBackupType" = "--full" ]
559
then
575
then
560
 ZimBackupFile=ZimBackupSystemFull_`date +%Y%m%d%H%M`.tar.gz
576
 ZimBackupFile=ZimBackupSystemFull_`date +%Y%m%d%H%M`.tar.gz
561
fi
577
fi
562
 
578
 
563
# Differential system backup
579
# Differential system backup
564
if [ "$ZimBackupType" = "--diff" ]
580
if [ "$ZimBackupType" = "--diff" ]
565
then
581
then
566
 ZimBackupFile=ZimBackupSystemDiff_`date +%Y%m%d%H%M`.tar.gz
582
 ZimBackupFile=ZimBackupSystemDiff_`date +%Y%m%d%H%M`.tar.gz
567
fi
583
fi
568
 
584
 
569
# Full message backup
585
# Full message backup
570
if [ "$ZimBackupType" = "--msg-full" ]
586
if [ "$ZimBackupType" = "--msg-full" ]
571
then
587
then
572
 ZimBackupFile=ZimBackupMsgFull_`date +%Y%m%d%H%M`.tar.gz
588
 ZimBackupFile=ZimBackupMsgFull_`date +%Y%m%d%H%M`.tar.gz
573
fi
589
fi
574
 
590
 
575
# Differential message backup
591
# Differential message backup
576
if [ "$ZimBackupType" = "--msg-diff" ]
592
if [ "$ZimBackupType" = "--msg-diff" ]
577
then
593
then
578
 ZimBackupFile=ZimBackupMsgDiff_`date +%Y%m%d%H%M`.tar.gz
594
 ZimBackupFile=ZimBackupMsgDiff_`date +%Y%m%d%H%M`.tar.gz
579
fi
595
fi
580
}
596
}
581
 
597
 
582
log_file() {
598
log_file() {
583
# Check to see if the log folder exist, create if not
599
# Check to see if the log folder exist, create if not
584
mkdir -p $ZimLogPath
600
mkdir -p $ZimLogPath
585
 
601
 
586
# Check log intervall and decide which file-name to use
602
# Check log intervall and decide which file-name to use
587
if [ "$ZimLogLogRotate" = "yes" ]
603
if [ "$ZimLogLogRotate" = "yes" ]
588
then
604
then
589
 
605
 
590
 # Set log file-name to day
606
 # Set log file-name to day
591
 if [ "$ZimLogRotateInt" = "day" ]
607
 if [ "$ZimLogRotateInt" = "day" ]
592
 then
608
 then
593
 
609
 
594
  # If file do not exist create it
610
  # If file do not exist create it
595
  touch $ZimLogPath/ZimBackupDay_`date +%Y-%m-%d`.log
611
  touch $ZimLogPath/ZimBackupDay_`date +%Y-%m-%d`.log
596
 
612
 
597
  # Set correct file-name
613
  # Set correct file-name
598
  ZimLogFile=$ZimLogPath/ZimBackupDay_`date +%Y-%m-%d`.log
614
  ZimLogFile=$ZimLogPath/ZimBackupDay_`date +%Y-%m-%d`.log
599
 fi
615
 fi
600
 
616
 
601
 # Set log file-name to week
617
 # Set log file-name to week
602
 if [ "$ZimLogRotateInt" = "week" ]
618
 if [ "$ZimLogRotateInt" = "week" ]
603
 then
619
 then
604
 
620
 
605
  # If file do not exist create it
621
  # If file do not exist create it
606
  touch $ZimLogPath/ZimBackupWeek_`date +%Y-%V`.log
622
  touch $ZimLogPath/ZimBackupWeek_`date +%Y-%V`.log
607
 
623
 
608
  # Set correct file-name
624
  # Set correct file-name
609
  ZimLogFile=$ZimLogPath/ZimBackupWeek_`date +%Y-%V`.log
625
  ZimLogFile=$ZimLogPath/ZimBackupWeek_`date +%Y-%V`.log
610
 fi
626
 fi
611
 
627
 
612
 # Set log file-name to month
628
 # Set log file-name to month
613
 if [ "$ZimLogRotateInt" = "month" ]
629
 if [ "$ZimLogRotateInt" = "month" ]
614
 then
630
 then
615
 
631
 
616
  # If file do not exist create it
632
  # If file do not exist create it
617
  touch $ZimLogPath/ZimBackupMonth_`date +%Y-%m`.log
633
  touch $ZimLogPath/ZimBackupMonth_`date +%Y-%m`.log
618
 
634
 
619
  # Set correct file-name
635
  # Set correct file-name
620
  ZimLogFile=$ZimLogPath/ZimBackupMonth_`date +%Y-%m`.log
636
  ZimLogFile=$ZimLogPath/ZimBackupMonth_`date +%Y-%m`.log
621
 fi
637
 fi
622
 
638
 
623
else
639
else
624
 
640
 
625
 # If file do not exist create it
641
 # If file do not exist create it
626
 touch $ZimLogPath/ZimBackup.log
642
 touch $ZimLogPath/ZimBackup.log
627
 
643
 
628
 # Set correct file-name
644
 # Set correct file-name
629
 ZimLogFile=$ZimLogPath/ZimBackup.log
645
 ZimLogFile=$ZimLogPath/ZimBackup.log
630
 
646
 
631
fi
647
fi
632
}
648
}
633
 
649
 
634
temp_folders() {
650
temp_folders() {
635
# Create & set temp folders under $ZimBackupPath
651
# Create & set temp folders under $ZimBackupPath
636
ZimFullTmpPath=$ZimBackupPath/tf
652
ZimFullTmpPath=$ZimBackupPath/tf
637
ZimDiffTmpPath=$ZimBackupPath/td
653
ZimDiffTmpPath=$ZimBackupPath/td
638
ZimMsgFullTmpPath=$ZimBackupPath/tmf
654
ZimMsgFullTmpPath=$ZimBackupPath/tmf
639
ZimMsgDiffTmpPath=$ZimBackupPath/tmd
655
ZimMsgDiffTmpPath=$ZimBackupPath/tmd
640
mkdir -p $ZimFullTmpPath
656
mkdir -p $ZimFullTmpPath
641
mkdir -p $ZimDiffTmpPath
657
mkdir -p $ZimDiffTmpPath
642
mkdir -p $ZimMsgFullTmpPath
658
mkdir -p $ZimMsgFullTmpPath
643
mkdir -p $ZimMsgDiffTmpPath
659
mkdir -p $ZimMsgDiffTmpPath
644
}
660
}
645
 
661
 
646
restore_guide() {
662
restore_guide() {
647
echo "Restore Guide"
663
echo "Restore Guide"
648
}
664
}
649
 
665
 
650
script_help() {
666
script_help() {
651
# Show help for script
667
# Show help for script
652
echo "oZimBackup.sh Usage:"
668
echo "oZimBackup.sh Usage:"
653
echo ""
669
echo ""
654
echo "--full			For full backup (Cold)"
670
echo "--full			For full backup (Cold)"
655
echo "--diff			For differential backup (Cold)"
671
echo "--diff			For differential backup (Cold)"
656
echo "--msg-full		For complete message backup (Hot)"
672
echo "--msg-full		For complete message backup (Hot)"
657
echo "--msg-diff		For differential message backup (Hot)"
673
echo "--msg-diff		For differential message backup (Hot)"
658
echo "--check			Check if needed software is installed, depends"
674
echo "--check			Check if needed software is installed, depends"
659
echo "				on script configuration"
675
echo "				on script configuration"
660
echo "--restore-guide		Shows a short guide on how to restore Zimbra"
676
echo "--restore-guide		Shows a short guide on how to restore Zimbra"
661
#echo "--full-restore		Does a complete restore"
677
#echo "--full-restore		Does a complete restore"
662
#echo "--diff-restore		Restores a differential backup"
678
#echo "--diff-restore		Restores a differential backup"
663
echo "--help			Shows this help"
679
echo "--help			Shows this help"
664
echo ""
680
echo ""
665
echo "--no-start		Tells Zimbra to stay offline after backup"
681
echo "--no-start		Tells Zimbra to stay offline after backup"
666
#echo "<file to restore>	File to restore from"
682
#echo "<file to restore>	File to restore from"
667
echo ""
683
echo ""
668
echo "Ex. Full backup:"
684
echo "Ex. Full backup:"
669
echo " oZimBackup.sh --full"
685
echo " oZimBackup.sh --full"
670
echo ""
686
echo ""
671
#echo "Ex. Complete restore:"
687
#echo "Ex. Complete restore:"
672
#echo " oZimBackup.sh --full-restore /path/to/file/zimbackup.tar.gz"
688
#echo " oZimBackup.sh --full-restore /path/to/file/zimbackup.tar.gz"
673
echo ""
689
echo ""
674
echo "Ex. Full differential backup leaving Zimbra in offline mode:"
690
echo "Ex. Full differential backup leaving Zimbra in offline mode:"
675
echo " oZimBackup.sh --diff --no-start"
691
echo " oZimBackup.sh --diff --no-start"
676
echo ""
692
echo ""
677
}
693
}
678
 
694
 
679
case $1 in
695
case $1 in
680
--full)
696
--full)
681
pre_check
697
pre_check
682
pre_load
698
pre_load
683
log_start
699
log_start
684
full_backup
700
full_backup
685
file_transfer
701
file_transfer
686
log_end
702
log_end
687
;;
703
;;
688
--diff)
704
--diff)
689
pre_check
705
pre_check
690
pre_load
706
pre_load
691
log_start
707
log_start
692
diff_backup
708
diff_backup
693
file_transfer
709
file_transfer
694
log_end
710
log_end
695
;;
711
;;
696
--msg-full)
712
--msg-full)
697
pre_check
713
pre_check
698
pre_load
714
pre_load
699
log_start
715
log_start
700
msgfull_backup
716
msgfull_backup
701
file_transfer
717
file_transfer
702
log_end
718
log_end
703
;;
719
;;
704
--msg-diff)
720
--msg-diff)
705
pre_check
721
pre_check
706
pre_load
722
pre_load
707
log_start
723
log_start
708
msgdiff_backup
724
msgdiff_backup
709
file_transfer
725
file_transfer
710
log_end
726
log_end
711
;;
727
;;
712
--full-restore)
728
--full-restore)
713
full_restore
729
full_restore
714
;;
730
;;
715
--diff-restore)
731
--diff-restore)
716
diff_restore
732
diff_restore
717
;;
733
;;
718
--restore-guide)
734
--restore-guide)
719
restore_guide
735
restore_guide
720
;;
736
;;
721
--check)
737
--check)
722
pre_check
738
pre_check
723
;;
739
;;
724
--help)
740
--help)
725
script_help
741
script_help
726
;;
742
;;
727
*)
743
*)
728
script_help
744
script_help
729
;;
745
;;
730
esac
746
esac