Subversion Repositories oZimbraBackup

Rev

Rev 4 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 4 Rev 5
Line 22... Line 22...
22
# Licensed under BSDL license, see license.txt for information.
22
# Licensed under BSDL license, see license.txt for information.
23
#
23
#
24
# Developer: oSource Development(as of 2009-07-01)
24
# Developer: oSource Development(as of 2009-07-01)
25
# DevTeam: Marcus Uddenhed
25
# DevTeam: Marcus Uddenhed
26
# Version: 1.0.7
26
# Version: 1.0.7
27
# Updated: 2015-12-14 22:17
27
# Updated: 2016-04-01 15:30
28
#
28
#
29
 
29
 
30
#### Global Settings ####
30
#### Global Settings ####
31
ZimInstPath=/opt			# Installation path for Zimbra, excluding the Zimbra folder.
31
ZimInstPath=/opt				# Installation path for Zimbra, excluding the Zimbra folder.
32
ZimHome=zimbra				# The Zimbra installation folder, excluding path to folder.
32
ZimHome=zimbra					# The Zimbra installation folder, excluding path to folder.
33
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.
34
 
34
 
35
#### Log Settings ####
35
#### Log Settings ####
36
ZimLogEnable=yes			# Turns logging on or off(yes/no).
36
ZimLogEnable=yes				# Turns logging on or off(yes/no).
37
ZimLogLogRotate=no			# Enables log rotating(yes/no)
37
ZimLogLogRotate=no				# Enables log rotating(yes/no)
38
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)
39
ZimLogPath=/opt/logs			# Folder for log files
39
ZimLogPath=/opt/backup/logs		# Folder for log files
40
ZimLogVerbose=no			# Activates extra logging information(yes/no)
40
ZimLogVerbose=no				# Activates extra logging information(yes/no)
41
 
41
 
42
#### File Transfer Settings ####
42
#### File Transfer Settings ####
43
 
43
 
44
# Enable Services (yes/no)
44
# Enable Services (yes/no)
45
ZimFtpEnable=no				# Enable/Disable ftp file transfer(yes/no)
45
ZimFtpEnable=no					# Enable/Disable ftp file transfer(yes/no)
46
ZimScpEnable=no				# Enable/Disable scp file transfer(yes/no)
46
ZimScpEnable=no					# Enable/Disable scp file transfer(yes/no)
47
 
47
 
48
# Extra FTP Settings
48
# Extra FTP Settings
49
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
50
 
50
 
51
# Extra SCP Settings
51
# Extra SCP Settings
52
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
53
 
53
 
54
# Common Settings
54
# Common Settings
55
ZimFilehostUser=			# Username for file transfers
55
ZimFilehostUser=				# Username for file transfers
56
ZimFilehostPass=			# Password for file transfers
56
ZimFilehostPass=				# Password for file transfers
57
ZimFilehostAddress=			# Host address for file transfers
57
ZimFilehostAddress=				# Host address for file transfers
58
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
59
 
59
 
60
#### File Delete Settings ####
60
#### File Delete Settings ####
61
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)
62
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,
63
					# be sure to match the time with your backup schedules.
63
								# be sure to match the time with your backup schedules.
64
 
64
 
65
##### 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 #####
66
 
66
 
67
# Fetch backup type
67
# Fetch backup type
68
ZimBackupType=$1
68
ZimBackupType=$1
Line 145... Line 145...
145
# Check which zimbra version that is installed, for recovery purposes
145
# Check which zimbra version that is installed, for recovery purposes
146
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
147
}
147
}
148
 
148
 
149
full_backup() {
149
full_backup() {
-
 
150
# Cleaning LDAP database from backup folder if exist.
-
 
151
if [ -f "$ZimDiffTmpPath/$ZimHome/data/ldap/mdb/db/data.mdb" ];
-
 
152
  then
-
 
153
    rm $ZimDiffTmpPath/$ZimHome/data/ldap/mdb/db/data.mdb
-
 
154
fi
-
 
155
 
-
 
156
# Making backup
150
if [ $ZimLogEnable = 'yes' ] && [ $ZimLogVerbose = 'yes' ]
157
if [ $ZimLogEnable = 'yes' ] && [ $ZimLogVerbose = 'yes' ]
151
 then
158
 then
152
 
159
 
153
   # Hot sync before shutdown on zimbra folder
160
   # Hot sync before shutdown on zimbra folder
154
   echo "`date "+%Y-%m-%d %H:%M:%S"` - Hot syncing to backup folder..." >> $ZimLogFile
161
   echo "`date "+%Y-%m-%d %H:%M:%S"` - Hot syncing to backup folder..." >> $ZimLogFile
155
   rsync -avHK --delete $ZimInstPath/$ZimHome $ZimFullTmpPath >> $ZimLogFile
162
   rsync -avHK --delete --exclude 'data/ldap/mdb/db/data.mdb' $ZimInstPath/$ZimHome $ZimFullTmpPath >> $ZimLogFile
156
   echo "`date "+%Y-%m-%d %H:%M:%S"` - Hot syncing to backup folder done." >> $ZimLogFile
163
   echo "`date "+%Y-%m-%d %H:%M:%S"` - Hot syncing to backup folder done." >> $ZimLogFile
157
 
164
 
158
   # Stopping Zimbra
165
   # Stopping Zimbra
159
   zimbra_stop
166
   zimbra_stop
160
 
167
 
161
   # Cold sync of zimbra folder
168
   # Cold sync of zimbra folder
162
   echo "`date "+%Y-%m-%d %H:%M:%S"` - Cold syncing to backup folder..." >> $ZimLogFile
169
   echo "`date "+%Y-%m-%d %H:%M:%S"` - Cold syncing to backup folder..." >> $ZimLogFile
163
   rsync -avHK --delete $ZimInstPath/$ZimHome $ZimFullTmpPath >> $ZimLogFile
170
   rsync -avHK --delete --exclude 'data/ldap/mdb/db/data.mdb' $ZimInstPath/$ZimHome $ZimFullTmpPath >> $ZimLogFile
-
 
171
   # Special LDAP DB copying needed.
-
 
172
   $ZimInstPath/$ZimHome/openldap/bin/mdb_copy $ZimInstPath/$ZimHome/data/ldap/mdb/db $ZimFullTmpPath/$ZimHome/data/ldap/mdb/db >> $ZimLogFile
164
   echo "`date "+%Y-%m-%d %H:%M:%S"` - Cold syncing to backup folder done." >> $ZimLogFile
173
   echo "`date "+%Y-%m-%d %H:%M:%S"` - Cold syncing to backup folder done." >> $ZimLogFile
165
 
174
 
166
   # Starting Zimbra
175
   # Starting Zimbra
167
   zimbra_start 
176
   zimbra_start
168
 
177
 
169
   # Compressing backup for space reduction
178
   # Compressing backup for space reduction
170
   echo "`date "+%Y-%m-%d %H:%M:%S"` - Compressing backup folder..." >> $ZimLogFile
179
   echo "`date "+%Y-%m-%d %H:%M:%S"` - Compressing backup folder..." >> $ZimLogFile
171
   tar -zcvpf $ZimBackupPath/$ZimBackupFile -C $ZimBackupPath tf zimbra_version.txt >> $ZimLogFile
180
   tar -zcvpf $ZimBackupPath/$ZimBackupFile -C $ZimBackupPath tf zimbra_version.txt >> $ZimLogFile
172
   echo "`date "+%Y-%m-%d %H:%M:%S"` - Compressed backup folder." >> $ZimLogFile
181
   echo "`date "+%Y-%m-%d %H:%M:%S"` - Compressed backup folder." >> $ZimLogFile
173
 
182
 
174
   # Cleaning differential folder.
183
   # Cleaning differential folder.
175
   echo "`date "+%Y-%m-%d %H:%M:%S"` - Cleaning differential backup folder..."
184
   echo "`date "+%Y-%m-%d %H:%M:%S"` - Cleaning differential backup folder..."
176
   rm -r -f $ZimDiffTmpPath/* >> $ZimLogFile
185
   rm -r -f $ZimDiffTmpPath/* >> $ZimLogFile
177
   echo "`date "+%Y-%m-%d %H:%M:%S"` - Cleaned differential backup folder."
186
   echo "`date "+%Y-%m-%d %H:%M:%S"` - Cleaned differential backup folder."
178
   
187
 
179
 else
188
 else
180
 
189
 
181
  # Hot sync before shutdown on zimbra folder
190
  # Hot sync before shutdown on zimbra folder
182
  rsync -avHK --delete $ZimInstPath/$ZimHome $ZimFullTmpPath
191
  rsync -avHK --delete --exclude 'data/ldap/mdb/db/data.mdb' $ZimInstPath/$ZimHome $ZimFullTmpPath
183
 
192
 
184
  # Stopping Zimbra
193
  # Stopping Zimbra
185
  zimbra_stop
194
  zimbra_stop
186
 
195
 
187
  # Cold sync of zimbra folder
196
  # Cold sync of zimbra folder
188
  rsync -avHK --delete $ZimInstPath/$ZimHome $ZimFullTmpPath
197
  rsync -avHK --delete --exclude 'data/ldap/mdb/db/data.mdb' $ZimInstPath/$ZimHome $ZimFullTmpPath
-
 
198
  # Special LDAP DB copying needed.
-
 
199
  $ZimInstPath/$ZimHome/openldap/bin/mdb_copy $ZimInstPath/$ZimHome/data/ldap/mdb/db $ZimFullTmpPath/$ZimHome/data/ldap/mdb/db
189
 
200
 
190
  # Starting Zimbra
201
  # Starting Zimbra
191
  zimbra_start
202
  zimbra_start
192
 
203
 
193
  # Compressing backup for space reduction
204
  # Compressing backup for space reduction
194
  tar -zcvpf $ZimBackupPath/$ZimBackupFile -C $ZimBackupPath tf zimbra_version.txt
205
  tar -zcvpf $ZimBackupPath/$ZimBackupFile -C $ZimBackupPath tf zimbra_version.txt
195
  
206
 
196
  # Cleaning differential folder.
207
  # Cleaning differential folder.
197
   rm -r -f $ZimDiffTmpPath/*
208
  rm -r -f $ZimDiffTmpPath/*
198
fi
209
fi
199
}
210
}
200
 
211
 
201
diff_backup() {
212
diff_backup() {
-
 
213
# Checking if LDAP database folder exist and fix it.
-
 
214
if [ ! -f "$ZimDiffTmpPath/$ZimHome/data/ldap/mdb/db/data.mdb" ];
-
 
215
  then
-
 
216
    if [ ! -d "$ZimDiffTmpPath/$ZimHome/data/ldap/mdb/db" ]
-
 
217
	  then
-
 
218
        mkdir -p $ZimDiffTmpPath/$ZimHome/data/ldap/mdb/db
-
 
219
    fi
-
 
220
else
-
 
221
  rm -R $ZimDiffTmpPath/$ZimHome/data/ldap/mdb/db/data.mdb
-
 
222
fi
-
 
223
 
-
 
224
# Make backup
202
if [ $ZimLogEnable = 'yes' ] && [ $ZimLogVerbose = 'yes' ]
225
if [ $ZimLogEnable = 'yes' ] && [ $ZimLogVerbose = 'yes' ]
203
 then
226
 then
204
  # Cleaning backup folder
-
 
205
  #echo "`date "+%Y-%m-%d %H:%M:%S"` - Cleaning backup folder..." >> $ZimLogFile
-
 
206
  #rm -r -f $ZimDiffTmpPath/* >> $ZimLogFile
-
 
207
  #echo "`date "+%Y-%m-%d %H:%M:%S"` - Cleaning backup folder done." >> $ZimLogFile
-
 
208
 
227
 
209
  # Hot syncing to backup folder
228
  # Hot syncing to backup folder
210
  echo "`date "+%Y-%m-%d %H:%M:%S"` - Hot syncing to backup folder..." >> $ZimLogFile
229
  echo "`date "+%Y-%m-%d %H:%M:%S"` - Hot syncing to backup folder..." >> $ZimLogFile
211
  rsync -avHK --compare-dest=$ZimFullTmpPath/ $ZimInstPath/$ZimHome $ZimDiffTmpPath >> $ZimLogFile
230
  rsync -avHK --exclude 'data/ldap/mdb/db/data.mdb' --compare-dest=$ZimFullTmpPath/ $ZimInstPath/$ZimHome $ZimDiffTmpPath >> $ZimLogFile
212
  echo "`date "+%Y-%m-%d %H:%M:%S"` - Hot syncing to backup folder done." >> $ZimLogFile
231
  echo "`date "+%Y-%m-%d %H:%M:%S"` - Hot syncing to backup folder done." >> $ZimLogFile
213
 
232
 
214
  # Stopping Zimbra
233
  # Stopping Zimbra
215
  zimbra_stop
234
  zimbra_stop
216
 
235
 
217
  # Cold syncing to backup folder
236
  # Cold syncing to backup folder
218
  echo "`date "+%Y-%m-%d %H:%M:%S"` - Cold syncing to backup folder..." >> $ZimLogFile
237
  echo "`date "+%Y-%m-%d %H:%M:%S"` - Cold syncing to backup folder..." >> $ZimLogFile
219
  rsync -avHK --compare-dest=$ZimFullTmpPath/ $ZimInstPath/$ZimHome $ZimDiffTmpPath >> $ZimLogFile
238
  rsync -avHK --exclude 'data/ldap/mdb/db/data.mdb' --compare-dest=$ZimFullTmpPath/ $ZimInstPath/$ZimHome $ZimDiffTmpPath >> $ZimLogFile
-
 
239
  # Special LDAP DB copying needed.
-
 
240
  $ZimInstPath/$ZimHome/openldap/bin/mdb_copy $ZimInstPath/$ZimHome/data/ldap/mdb/db $ZimDiffTmpPath/$ZimHome/data/ldap/mdb/db >> $ZimLogFile
220
  echo "`date "+%Y-%m-%d %H:%M:%S"` - Cold syncing to backup folder done." >> $ZimLogFile
241
  echo "`date "+%Y-%m-%d %H:%M:%S"` - Cold syncing to backup folder done." >> $ZimLogFile
221
 
242
 
222
  # Starting Zimbra
243
  # Starting Zimbra
223
  zimbra_start
244
  zimbra_start
224
 
245
 
225
  # Syncing backup folders
-
 
226
  #echo "`date "+%Y-%m-%d %H:%M:%S"` - Syncing backup folders..." >> $ZimLogFile
-
 
227
  #cp -R $ZimDiffTmpPath/* $ZimFullTmpPath/ >> $ZimLogFile
-
 
228
  #echo "`date "+%Y-%m-%d %H:%M:%S"` - Syncing backup folders done." >> $ZimLogFile
-
 
229
 
-
 
230
  # Compressing backup folder
246
  # Compressing backup folder
231
  echo "`date "+%Y-%m-%d %H:%M:%S"` - Compressing backup folder..." >> $ZimLogFile
247
  echo "`date "+%Y-%m-%d %H:%M:%S"` - Compressing backup folder..." >> $ZimLogFile
232
  tar -zcvpf $ZimBackupPath/$ZimBackupFile -C $ZimBackupPath td zimbra_version.txt >> $ZimLogFile
248
  tar -zcvpf $ZimBackupPath/$ZimBackupFile -C $ZimBackupPath td zimbra_version.txt >> $ZimLogFile
233
  echo "`date "+%Y-%m-%d %H:%M:%S"` - Compressing backup folder done." >> $ZimLogFile
249
  echo "`date "+%Y-%m-%d %H:%M:%S"` - Compressing backup folder done." >> $ZimLogFile
234
 
250
 
235
 else
251
 else
236
 
252
 
237
  # Hot sync before shutdown on zimbra folder
253
  # Hot sync before shutdown on zimbra folder
238
  #rm -R $ZimDiffTmpPath/*
254
  #rm -R $ZimDiffTmpPath/*
239
  rsync -avHK --compare-dest=$ZimFullTmpPath/ $ZimInstPath/$ZimHome $ZimDiffTmpPath
255
  rsync -avHK --exclude 'data/ldap/mdb/db/data.mdb' --compare-dest=$ZimFullTmpPath/ $ZimInstPath/$ZimHome $ZimDiffTmpPath
240
 
256
 
241
  # Stopping Zimbra
257
  # Stopping Zimbra
242
  zimbra_stop
258
  zimbra_stop
243
 
259
 
244
  # Cold sync of zimbra folder
260
  # Cold sync of zimbra folder
245
  rsync -avHK --compare-dest=$ZimFullTmpPath/ $ZimInstPath/$ZimHome $ZimDiffTmpPath
261
  rsync -avHK --exclude 'data/ldap/mdb/db/data.mdb' --compare-dest=$ZimFullTmpPath/ $ZimInstPath/$ZimHome $ZimDiffTmpPath
246
 
-
 
-
 
262
  # Special LDAP DB copying needed.
-
 
263
  $ZimInstPath/$ZimHome/openldap/bin/mdb_copy $ZimInstPath/$ZimHome/data/ldap/mdb/db $ZimDiffTmpPath/$ZimHome/data/ldap/mdb/db
247
  # Starting Zimbra
264
  # Starting Zimbra
248
  zimbra_start
265
  zimbra_start
249
 
266
 
250
  # Syncing files from diff to full backup folder
-
 
251
  #cp -R $ZimDiffTmpPath/* $ZimFullTmpPath/
-
 
252
 
-
 
253
  # Compressing backup for space reduction
267
  # Compressing backup for space reduction
254
  tar -zcvpf $ZimBackupPath/$ZimBackupFile -C $ZimBackupPath td zimbra_version.txt
268
  tar -zcvpf $ZimBackupPath/$ZimBackupFile -C $ZimBackupPath td zimbra_version.txt
255
fi
269
fi
256
}
270
}
257
 
271
 
Line 265... Line 279...
265
 
279
 
266
  # Compressing backup folder
280
  # Compressing backup folder
267
  echo "`date "+%Y-%m-%d %H:%M:%S"` - Compressing backup folder..." >> $ZimLogFile
281
  echo "`date "+%Y-%m-%d %H:%M:%S"` - Compressing backup folder..." >> $ZimLogFile
268
  tar -zcvpf $ZimBackupPath/$ZimBackupFile -C $ZimBackupPath tmf zimbra_version.txt >> $ZimLogFile
282
  tar -zcvpf $ZimBackupPath/$ZimBackupFile -C $ZimBackupPath tmf zimbra_version.txt >> $ZimLogFile
269
  echo "`date "+%Y-%m-%d %H:%M:%S"` - Compressing backup folder done." >> $ZimLogFile
283
  echo "`date "+%Y-%m-%d %H:%M:%S"` - Compressing backup folder done." >> $ZimLogFile
270
  
284
 
271
  echo "`date "+%Y-%m-%d %H:%M:%S"` - Cleaning differential backup folder..."
285
  echo "`date "+%Y-%m-%d %H:%M:%S"` - Cleaning differential backup folder..."
272
  rm -r -f $ZimMsgDiffTmpPath/* >> $ZimLogFile
286
  rm -r -f $ZimMsgDiffTmpPath/* >> $ZimLogFile
273
  echo "`date "+%Y-%m-%d %H:%M:%S"` - Cleaned differential backup folder."
287
  echo "`date "+%Y-%m-%d %H:%M:%S"` - Cleaned differential backup folder."
274
 
288
 
275
 else
289
 else
276
  # Hot syncing to backup folder
290
  # Hot syncing to backup folder
277
  rsync -avHK --delete $ZimInstPath/$ZimHome/store $ZimMsgFullTmpPath
291
  rsync -avHK --delete $ZimInstPath/$ZimHome/store $ZimMsgFullTmpPath
278
 
292
 
279
  # Compressing backup folder
293
  # Compressing backup folder
280
  tar -zcvpf $ZimBackupPath/$ZimBackupFile -C $ZimBackupPath tmf zimbra_version.txt
294
  tar -zcvpf $ZimBackupPath/$ZimBackupFile -C $ZimBackupPath tmf zimbra_version.txt
281
  
295
 
282
  # Cleaning differential folder
296
  # Cleaning differential folder
283
  rm -r -f $ZimMsgDiffTmpPath/*
297
  rm -r -f $ZimMsgDiffTmpPath/*
284
fi
298
fi
285
}
299
}
286
 
300
 
Line 557... Line 571...
557
  sleep 10
571
  sleep 10
558
 
572
 
559
fi
573
fi
560
}
574
}
561
 
575
 
562
full_restore() {
-
 
563
echo "Full Restore under development"
-
 
564
}
-
 
565
 
-
 
566
diff_restore() {
-
 
567
echo "Diff Restore under development"
-
 
568
}
-
 
569
 
-
 
570
backup_file() {
576
backup_file() {
571
# Checks what backup is choosen and sets file-name appropiate
577
# Checks what backup is choosen and sets file-name appropiate
572
 
578
 
573
# Full system backup
579
# Full system backup
574
if [ "$ZimBackupType" = "--full" ]
580
if [ "$ZimBackupType" = "--full" ]