Subversion Repositories oZimbraBackup

Rev

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.1
26
# Last updated: 2010-08-06 11:13
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
 else
173
 
174
  # Hot sync before shutdown on zimbra folder
175
  rsync -avHK --delete $ZimInstPath/$ZimHome $ZimFullTmpPath
176
 
177
  # Stopping Zimbra
178
  zimbra_stop
179
 
180
  # Cold sync of zimbra folder
181
  rsync -avHK --delete $ZimInstPath/$ZimHome $ZimFullTmpPath
182
 
183
  # Starting Zimbra
184
  zimbra_start
185
 
186
  # Compressing backup for space reduction
187
  tar -zcvpf $ZimBackupPath/$ZimBackupFile -C $ZimBackupPath tf zimbra_version.txt
188
fi
189
}
190
 
191
diff_backup() {
192
if [ $ZimLogEnable = 'yes' ] && [ $ZimLogVerbose = 'yes' ]
193
 then
194
  # Cleaning backup folder
195
  echo "`date "+%Y-%m-%d %H:%M:%S"` - Cleaning backup folder..." >> $ZimLogFile
196
  rm -r -f $ZimDiffTmpPath/* >> $ZimLogFile
197
  echo "`date "+%Y-%m-%d %H:%M:%S"` - Cleaning backup folder done." >> $ZimLogFile
198
 
199
  # Hot syncing to backup folder
200
  echo "`date "+%Y-%m-%d %H:%M:%S"` - Hot syncing to backup folder..." >> $ZimLogFile
201
  rsync -avHK --delete --compare-dest=$ZimFullTmpPath/ $ZimInstPath/$ZimHome $ZimDiffTmpPath >> $ZimLogFile
202
  echo "`date "+%Y-%m-%d %H:%M:%S"` - Hot syncing to backup folder done." >> $ZimLogFile
203
 
204
  # Stopping Zimbra
205
  zimbra_stop
206
 
207
  # Cold syncing to backup folder
208
  echo "`date "+%Y-%m-%d %H:%M:%S"` - Cold syncing to backup folder..." >> $ZimLogFile
209
  rsync -avHK --delete --compare-dest=$ZimFullTmpPath/ $ZimInstPath/$ZimHome $ZimDiffTmpPath >> $ZimLogFile
210
  echo "`date "+%Y-%m-%d %H:%M:%S"` - Cold syncing to backup folder done." >> $ZimLogFile
211
 
212
  # Starting Zimbra
213
  zimbra_start
214
 
215
  # Syncing backup folders
216
  echo "`date "+%Y-%m-%d %H:%M:%S"` - Syncing backup folders..." >> $ZimLogFile
217
  cp -R $ZimDiffTmpPath/* $ZimFullTmpPath/ >> $ZimLogFile
218
  echo "`date "+%Y-%m-%d %H:%M:%S"` - Syncing backup folders done." >> $ZimLogFile
219
 
220
  # Compressing backup folder
221
  echo "`date "+%Y-%m-%d %H:%M:%S"` - Compressing backup folder..." >> $ZimLogFile
222
  tar -zcvpf $ZimBackupPath/$ZimBackupFile -C $ZimBackupPath td zimbra_version.txt >> $ZimLogFile
223
  echo "`date "+%Y-%m-%d %H:%M:%S"` - Compressing backup folder done." >> $ZimLogFile
224
 
225
 else
226
 
227
  # Hot sync before shutdown on zimbra folder
228
  rm -R $ZimDiffTmpPath/*
229
  rsync -avHK --delete --compare-dest=$ZimFullTmpPath/ $ZimInstPath/$ZimHome $ZimDiffTmpPath
230
 
231
  # Stopping Zimbra
232
  zimbra_stop
233
 
234
  # Cold sync of zimbra folder
235
  rsync -avHK --delete --compare-dest=$ZimFullTmpPath/ $ZimInstPath/$ZimHome $ZimDiffTmpPath
236
 
237
  # Starting Zimbra
238
  zimbra_start
239
 
240
  # Syncing files from diff to full backup folder
241
  cp -R $ZimDiffTmpPath/* $ZimFullTmpPath/
242
 
243
  # Compressing backup for space reduction
244
  tar -zcvpf $ZimBackupPath/$ZimBackupFile -C $ZimBackupPath td zimbra_version.txt
245
fi
246
}
247
 
248
msgfull_backup() {
249
if [ $ZimLogEnable = 'yes' ] && [ $ZimLogVerbose = 'yes' ]
250
 then
251
  # Hot syncing to backup folder
252
  echo "`date "+%Y-%m-%d %H:%M:%S"` - Hot syncing to backup folder..." >> $ZimLogFile
253
  rsync -avHK --delete $ZimInstPath/$ZimHome/store $ZimMsgFullTmpPath >> $ZimLogFile
254
  echo "`date "+%Y-%m-%d %H:%M:%S"` - Hot syncing to backup folder done." >> $ZimLogFile
255
 
256
  # Compressing backup folder
257
  echo "`date "+%Y-%m-%d %H:%M:%S"` - Compressing backup folder..." >> $ZimLogFile
258
  tar -zcvpf $ZimBackupPath/$ZimBackupFile -C $ZimBackupPath tmf zimbra_version.txt >> $ZimLogFile
259
  echo "`date "+%Y-%m-%d %H:%M:%S"` - Compressing backup folder done." >> $ZimLogFile
260
 
261
 else
262
  # Hot syncing to backup folder
263
  rsync -avHK --delete $ZimInstPath/$ZimHome/store $ZimMsgFullTmpPath
264
 
265
  # Compressing backup folder
266
  tar -zcvpf $ZimBackupPath/$ZimBackupFile -C $ZimBackupPath tmf zimbra_version.txt
267
fi
268
}
269
 
270
msgdiff_backup() {
271
if [ $ZimLogEnable = 'yes' ] && [ $ZimLogVerbose = 'yes' ]
272
 then
273
  # Cleaning backup folder
274
  echo "`date "+%Y-%m-%d %H:%M:%S"` - Cleaning backup folder..." >> $ZimLogFile
275
  rm -r -f $ZimMsgDiffTmpPath/* >> $ZimLogFile
276
  echo "`date "+%Y-%m-%d %H:%M:%S"` - Cleaning backup folder done." >> $ZimLogFile
277
 
278
  # Hot syncing to backup folder
279
  echo "`date "+%Y-%m-%d %H:%M:%S"` - Hot syncing to backup folder..." >> $ZimLogFile
280
  rsync -avHK --delete --compare-dest=$ZimMsgFullTmpPath/ $ZimInstPath/$ZimHome/store $ZimMsgDiffTmpPath >> $ZimLogFile
281
  echo "`date "+%Y-%m-%d %H:%M:%S"` - Hot syncing to backup folder done." >> $ZimLogFile
282
 
283
  # Compressing backup folder
284
  echo "`date "+%Y-%m-%d %H:%M:%S"` - Compressing backup folder..." >> $ZimLogFile
285
  tar -zcvpf $ZimBackupPath/$ZimBackupFile -C $ZimBackupPath tmd zimbra_version.txt >> $ZimLogFile
286
  echo "`date "+%Y-%m-%d %H:%M:%S"` - Compressing backup folder done." >> $ZimLogFile
287
 
288
 else
289
  # Cleaning backup folder
290
  rm -r -f $ZimMsgDiffTmpPath/*
291
 
292
  # Hot syncing to backup folder
293
  rsync -avHK --delete --compare-dest=$ZimMsgFullTmpPath/ $ZimInstPath/$ZimHome/store $ZimMsgDiffTmpPath
294
 
295
  # Compressing backup folder
296
  tar -zcvpf $ZimBackupPath/$ZimBackupFile -C $ZimBackupPath tmd zimbra_version.txt
297
fi
298
}
299
 
300
file_transfer() {
301
# Transfer with ftp
302
if [ $ZimFtpEnable == "yes" ]
303
then
304
if [ $ZimLogEnable = 'yes' ] && [ $ZimLogVerbose = 'yes' ]
305
 then
306
  # Send task start time to log
307
  echo "`date "+%Y-%m-%d %H:%M:%S"` - Sending file via ftp to off-site storage..." >> $ZimLogFile
308
 
309
  # Make a temporary script for expect commands
310
  touch $ZimBackupPath/ftp.exp
311
 
312
  # Fill script with commands
313
  echo '#!/usr/bin/expect --' >> $ZimBackupPath/ftp.exp
314
  echo 'set timeout -1' >> $ZimBackupPath/ftp.exp
315
  echo 'spawn ftp '$ZimFilehostAddress >> $ZimBackupPath/ftp.exp
316
  echo 'expect ):' >> $ZimBackupPath/ftp.exp
317
  echo 'send '$ZimFilehostUser'\r' >> $ZimBackupPath/ftp.exp
318
  echo 'expect :' >> $ZimBackupPath/ftp.exp
319
  echo 'send '$ZimFilehostPass'\r' >> $ZimBackupPath/ftp.exp
320
  echo 'expect >' >> $ZimBackupPath/ftp.exp
321
  echo 'send '$ZimFtpOpt'\r' >> $ZimBackupPath/ftp.exp
322
  echo 'send "send '$ZimBackupPath/$ZimBackupFile $ZimFilehostFolder/$ZimBackupFile'\r"' >> $ZimBackupPath/ftp.exp
323
  echo 'expect >' >> $ZimBackupPath/ftp.exp
324
  echo 'send quit\r' >> $ZimBackupPath/ftp.exp
325
  echo 'expect closed' >> $ZimBackupPath/ftp.exp
326
 
327
  # Run expect with created script
328
  expect $ZimBackupPath/ftp.exp >> $ZimLogFile
329
 
330
  # Delete temporary expect script
331
  rm $ZimBackupPath/ftp.exp
332
 
333
  # Send task stop time to log
334
  echo "`date "+%Y-%m-%d %H:%M:%S"` - Sending file via ftp to off-site storage done." >> $ZimLogFile
335
 
336
 else
337
 
338
  # Make a temporary script for expect commands
339
  touch $ZimBackupPath/ftp.exp
340
 
341
  # Fill script with commands
342
  echo '#!/usr/bin/expect --' >> $ZimBackupPath/ftp.exp
343
  echo 'set timeout -1' >> $ZimBackupPath/ftp.exp
344
  echo 'spawn ftp '$ZimFilehostAddress >> $ZimBackupPath/ftp.exp
345
  echo 'expect ):' >> $ZimBackupPath/ftp.exp
346
  echo 'send '$ZimFilehostUser'\r' >> $ZimBackupPath/ftp.exp
347
  echo 'expect :' >> $ZimBackupPath/ftp.exp
348
  echo 'send '$ZimFilehostPass'\r' >> $ZimBackupPath/ftp.exp
349
  echo 'expect >' >> $ZimBackupPath/ftp.exp
350
  echo 'send '$ZimFtpOpt'\r' >> $ZimBackupPath/ftp.exp
351
  echo 'send "send '$ZimBackupPath/$ZimBackupFile $ZimFilehostFolder/$ZimBackupFile'\r"' >> $ZimBackupPath/ftp.exp
352
  echo 'expect >' >> $ZimBackupPath/ftp.exp
353
  echo 'send quit\r' >> $ZimBackupPath/ftp.exp
354
  echo 'expect closed' >> $ZimBackupPath/ftp.exp
355
 
356
  # Run expect with created script
357
  expect $ZimBackupPath/ftp.exp
358
 
359
  # Delete temporary expect script
360
  rm $ZimBackupPath/ftp.exp
361
 fi
362
fi
363
 
364
# Transfer with scp
365
if [ $ZimScpEnable == "yes" ]
366
then
367
 if [ $ZimLogEnable = 'yes' ] && [ $ZimLogVerbose = 'yes' ]
368
  then
369
 
370
  # Send task start time to log
371
   echo "`date "+%Y-%m-%d %H:%M:%S"` - Sending file via scp to off-site storage..." >> $ZimLogFile
372
 
373
   # Make a temporary script for expect commands
374
   touch $ZimBackupPath/scp.exp
375
 
376
   # Fill script with commands
377
   echo '#!/usr/bin/expect --' >> $ZimBackupPath/scp.exp
378
   echo 'set timeout -1' >> $ZimBackupPath/scp.exp
379
   echo 'spawn scp '$ZimScpOpt $ZimBackupPath/$ZimBackupFile $ZimFilehostUser'@'$ZimFilehostAddress':'$ZimFilehostFolder >> $ZimBackupPath/scp.exp
380
   echo 'expect :' >> $ZimBackupPath/scp.exp
381
   echo 'send '$ZimFilehostPass'\r' >> $ZimBackupPath/scp.exp
382
   echo 'expect closed' >> $ZimBackupPath/scp.exp
383
 
384
   # Run expect with created script
385
   expect $ZimBackupPath/scp.exp >> $ZimLogFile
386
 
387
   # Delete temporary expect script
388
   rm $ZimBackupPath/scp.exp
389
 
390
  # Send task stop time to log
391
   echo "`date "+%Y-%m-%d %H:%M:%S"` - Sending file via scp to off-site storage done." >> $ZimLogFile
392
 
393
  else
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
408
 
409
   # Delete temporary expect script
410
   rm $ZimBackupPath/scp.exp
411
 fi
412
fi
413
 
414
# Remove local file(s) if ZimDeleteLocalFile is set to 'yes'
415
if [ $ZimDeleteLocalFile == "yes" ]
416
then
417
 if [ $ZimLogEnable = 'yes' ] && [ $ZimLogVerbose = 'yes' ]
418
  then
419
 
420
  # Send task start time to log
421
   echo "`date "+%Y-%m-%d %H:%M:%S"` - Deleting local file(s)..." >> $ZimLogFile
422
 
423
   # Remove backup files matching criteria
424
   find $ZimBackupPath -maxdepth 1 -type f -mmin +$ZimDeleteTimeSet -name ZimBackup\*.tar.gz -exec rm {} +  >> $ZimLogFile
425
 
426
   # Send task stop time to log
427
   echo "`date "+%Y-%m-%d %H:%M:%S"` - Deleting local file(s) done." >> $ZimLogFile
428
 
429
  else
430
 
431
   # Remove backup files matching criteria
432
   find $ZimBackupPath -maxdepth 1 -type f -mmin +$ZimDeleteTimeSet -name ZimBackup\*.tar.gz -exec rm {} +
433
 
434
 fi
435
fi
436
}
437
 
438
log_start() {
439
if [ $ZimLogEnable = 'yes' ]
440
 then
441
 
442
  # Sending backup start time to log
443
  echo "" >> $ZimLogFile
444
  echo "-------------------------------------------------------" >> $ZimLogFile
445
  echo "Backup Started: `date "+%Y-%m-%d %H:%M:%S"` Type: $ZimBackupType" >> $ZimLogFile
446
 
447
fi
448
}
449
 
450
log_end() {
451
if [ $ZimLogEnable = 'yes' ]
452
 then
453
 
454
  # Sending backup stop time to log
455
  echo "Backup Finished: `date "+%Y-%m-%d %H:%M:%S"` Type: $ZimBackupType" >> $ZimLogFile
456
  echo "-------------------------------------------------------" >> $ZimLogFile
457
 
458
fi
459
}
460
 
461
zimbra_start() {
462
if [ "$2" = "--no-start" ]
463
then
464
  # If --no-start is set ignore starting Zimbra
465
  echo "`date "+%Y-%m-%d %H:%M:%S"` - Zimbra services not starting, --no-start is set." >> $ZimLogFile
466
  echo "Zimbra services not starting, --no-start is set."
467
else
468
 # Starting Zimbra
469
 if [ $ZimLogEnable = 'yes' ]
470
  then
471
   # Sending task start time to log
472
   echo "`date "+%Y-%m-%d %H:%M:%S"` - Zimbra services starting..." >> $ZimLogFile
473
 
474
   # Starting Zimbra
475
   sudo -u zimbra /opt/zimbra/bin/zmcontrol start >> $ZimLogFile
476
 
477
   # Send task stop time to log
478
   echo "`date "+%Y-%m-%d %H:%M:%S"` - Zimbra services started." >> $ZimLogFile
479
 
480
  else
481
 
482
   # Starting Zimbra
483
   sudo -u zimbra /opt/zimbra/bin/zmcontrol start
484
 
485
  fi
486
fi
487
}
488
 
489
zimbra_stop() {
490
# Stopping Zimbra
491
if [ $ZimLogEnable = 'yes' ]
492
 then
493
 
494
  # Sending task start time to log
495
  echo "`date "+%Y-%m-%d %H:%M:%S"` - Zimbra services stopping..." >> $ZimLogFile
496
 
497
  # Stopping Zimbra
498
  #/etc/init.d/zimbra stop >> $ZimLogFile
499
  sudo -u zimbra /opt/zimbra/bin/zmcontrol stop >> $ZimLogFile
500
 
501
  # Sending task stop time to log
502
  echo "`date "+%Y-%m-%d %H:%M:%S"` - Zimbra services stopped." >> $ZimLogFile
503
 
504
  # Sleep for to give shutdown some extra time before backup starts
505
  sleep 10
506
 
507
else
508
 
509
  # Stopping Zimbra
510
  sudo -u zimbra /opt/zimbra/bin/zmcontrol stop
511
 
512
fi
513
}
514
 
515
full_restore() {
516
echo "Full Restore under development"
517
}
518
 
519
diff_restore() {
520
echo "Diff Restore under development"
521
}
522
 
523
backup_file() {
524
# Checks what backup is choosen and sets file-name appropiate
525
 
526
# Full system backup
527
if [ "$ZimBackupType" = "--full" ]
528
then
529
 ZimBackupFile=ZimBackupSystemFull_`date +%Y%m%d%H%M`.tar.gz
530
fi
531
 
532
# Differential system backup
533
if [ "$ZimBackupType" = "--diff" ]
534
then
535
 ZimBackupFile=ZimBackupSystemDiff_`date +%Y%m%d%H%M`.tar.gz
536
fi
537
 
538
# Full message backup
539
if [ "$ZimBackupType" = "--msg-full" ]
540
then
541
 ZimBackupFile=ZimBackupMsgFull_`date +%Y%m%d%H%M`.tar.gz
542
fi
543
 
544
# Differential message backup
545
if [ "$ZimBackupType" = "--msg-diff" ]
546
then
547
 ZimBackupFile=ZimBackupMsgDiff_`date +%Y%m%d%H%M`.tar.gz
548
fi
549
}
550
 
551
log_file() {
552
# Check to see if the log folder exist, create if not
553
mkdir -p $ZimLogPath
554
 
555
# Check log intervall and decide which file-name to use
556
if [ "$ZimLogLogRotate" = "yes" ]
557
then
558
 
559
 # Set log file-name to day
560
 if [ "$ZimLogRotateInt" = "day" ]
561
 then
562
 
563
  # If file do not exist create it
564
  touch $ZimLogPath/ZimBackupDay_`date +%Y-%m-%d`.log
565
 
566
  # Set correct file-name
567
  ZimLogFile=$ZimLogPath/ZimBackupDay_`date +%Y-%m-%d`.log
568
 fi
569
 
570
 # Set log file-name to week
571
 if [ "$ZimLogRotateInt" = "week" ]
572
 then
573
 
574
  # If file do not exist create it
575
  touch $ZimLogPath/ZimBackupWeek_`date +%Y-%V`.log
576
 
577
  # Set correct file-name
578
  ZimLogFile=$ZimLogPath/ZimBackupWeek_`date +%Y-%V`.log
579
 fi
580
 
581
 # Set log file-name to month
582
 if [ "$ZimLogRotateInt" = "month" ]
583
 then
584
 
585
  # If file do not exist create it
586
  touch $ZimLogPath/ZimBackupMonth_`date +%Y-%m`.log
587
 
588
  # Set correct file-name
589
  ZimLogFile=$ZimLogPath/ZimBackupMonth_`date +%Y-%m`.log
590
 fi
591
 
592
else
593
 
594
 # If file do not exist create it
595
 touch $ZimLogPath/ZimBackup.log
596
 
597
 # Set correct file-name
598
 ZimLogFile=$ZimLogPath/ZimBackup.log
599
 
600
fi
601
}
602
 
603
temp_folders() {
604
# Create & set temp folders under $ZimBackupPath
605
ZimFullTmpPath=$ZimBackupPath/tf
606
ZimDiffTmpPath=$ZimBackupPath/td
607
ZimMsgFullTmpPath=$ZimBackupPath/tmf
608
ZimMsgDiffTmpPath=$ZimBackupPath/tmd
609
mkdir -p $ZimFullTmpPath
610
mkdir -p $ZimDiffTmpPath
611
mkdir -p $ZimMsgFullTmpPath
612
mkdir -p $ZimMsgDiffTmpPath
613
}
614
 
615
 
616
restore_guide() {
617
echo "Restore Guide"
618
}
619
 
620
script_help() {
621
# Show help for script
622
echo "oZimBackup.sh Usage:"
623
echo ""
624
echo "--full			For full backup (Cold)"
625
echo "--diff			For differential backup (Cold)"
626
echo "--msg-full		For complete message backup (Hot)"
627
echo "--msg-diff		For differential message backup (Hot)"
628
echo "--check			Check if needed software is installed, depends"
629
echo "				on script configuration"
630
echo "--restore-guide		Shows a short guide on how to restore Zimbra"
631
#echo "--full-restore		Does a complete restore"
632
#echo "--diff-restore		Restores a differential backup"
633
echo "--help			Shows this help"
634
echo ""
635
echo "--no-start		Tells Zimbra to stay offline after backup"
636
#echo "<file to restore>	File to restore from"
637
echo ""
638
echo "Ex. Full backup:"
639
echo " oZimBackup.sh --full"
640
echo ""
641
#echo "Ex. Complete restore:"
642
#echo " oZimBackup.sh --full-restore /path/to/file/zimbackup.tar.gz"
643
echo ""
644
echo "Ex. Full differential backup leaving Zimbra in offline mode:"
645
echo " oZimBackup.sh --diff --no-start"
646
echo ""
647
}
648
 
649
case $1 in
650
--full)
651
pre_check
652
pre_load
653
log_start
654
full_backup
655
file_transfer
656
log_end
657
;;
658
--diff)
659
pre_check
660
pre_load
661
log_start
662
diff_backup
663
file_transfer
664
log_end
665
;;
666
--msg-full)
667
pre_check
668
pre_load
669
log_start
670
msgfull_backup
671
file_transfer
672
log_end
673
;;
674
--msg-diff)
675
pre_check
676
pre_load
677
log_start
678
msgdiff_backup
679
file_transfer
680
log_end
681
;;
682
--full-restore)
683
full_restore
684
;;
685
--diff-restore)
686
diff_restore
687
;;
688
--restore-guide)
689
restore_guide
690
;;
691
--check)
692
pre_check
693
;;
694
--help)
695
script_help
696
;;
697
*)
698
script_help
699
;;
700
esac