Subversion Repositories oZimbraBackup

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

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