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
#
Line 29... Line 29...
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.
Line 33... Line 33...
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)
Line 39... Line 39...
39
ZimLogPath=/opt/logs			# Folder for log files
39
ZimLogPath=/opt/backup/logs		# Folder for log files
Line 40... Line 40...
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 ####
Line 43... Line 43...
43
 
43
 
44
# Enable Services (yes/no)
44
# Enable Services (yes/no)
Line 45... Line 45...
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)
Line 47... Line 47...
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
Line 52... Line 52...
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
Line 56... Line 56...
56
ZimFilehostPass=			# Password for file transfers
56
ZimFilehostPass=				# Password for file transfers
Line 57... Line 57...
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
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
}
Line 148... Line 148...
148
 
148
 
-
 
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
 
149
full_backup() {
156
# Making backup
150
if [ $ZimLogEnable = 'yes' ] && [ $ZimLogVerbose = 'yes' ]
157
if [ $ZimLogEnable = 'yes' ] && [ $ZimLogVerbose = 'yes' ]
Line 151... Line 158...
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
Line 155... Line 162...
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
Line 157... Line 164...
157
 
164
 
158
   # Stopping Zimbra
165
   # Stopping Zimbra
159
   zimbra_stop
166
   zimbra_stop
-
 
167
 
-
 
168
   # Cold sync of zimbra folder
160
 
169
   echo "`date "+%Y-%m-%d %H:%M:%S"` - Cold syncing to backup folder..." >> $ZimLogFile
Line 161... Line 170...
161
   # Cold sync of zimbra folder
170
   rsync -avHK --delete --exclude 'data/ldap/mdb/db/data.mdb' $ZimInstPath/$ZimHome $ZimFullTmpPath >> $ZimLogFile
162
   echo "`date "+%Y-%m-%d %H:%M:%S"` - Cold syncing to backup folder..." >> $ZimLogFile
171
   # Special LDAP DB copying needed.
Line 163... Line 172...
163
   rsync -avHK --delete $ZimInstPath/$ZimHome $ZimFullTmpPath >> $ZimLogFile
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
Line 167... Line 176...
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
Line 173... Line 182...
173
 
182
 
174
   # Cleaning differential folder.
183
   # Cleaning differential folder.
Line 175... Line 184...
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
Line 177... Line 186...
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
 
-
 
188
 else
-
 
189
 
Line 179... Line 190...
179
 else
190
  # Hot sync before shutdown on zimbra folder
180
 
191
  rsync -avHK --delete --exclude 'data/ldap/mdb/db/data.mdb' $ZimInstPath/$ZimHome $ZimFullTmpPath
Line 181... Line 192...
181
  # Hot sync before shutdown on zimbra folder
192
 
182
  rsync -avHK --delete $ZimInstPath/$ZimHome $ZimFullTmpPath
193
  # Stopping Zimbra
183
 
194
  zimbra_stop
184
  # Stopping Zimbra
195
 
185
  zimbra_stop
196
  # Cold sync of zimbra folder
186
 
197
  rsync -avHK --delete --exclude 'data/ldap/mdb/db/data.mdb' $ZimInstPath/$ZimHome $ZimFullTmpPath
187
  # Cold sync of zimbra folder
198
  # Special LDAP DB copying needed.
Line 188... Line 199...
188
  rsync -avHK --delete $ZimInstPath/$ZimHome $ZimFullTmpPath
199
  $ZimInstPath/$ZimHome/openldap/bin/mdb_copy $ZimInstPath/$ZimHome/data/ldap/mdb/db $ZimFullTmpPath/$ZimHome/data/ldap/mdb/db
-
 
200
 
-
 
201
  # Starting Zimbra
-
 
202
  zimbra_start
-
 
203
 
-
 
204
  # Compressing backup for space reduction
-
 
205
  tar -zcvpf $ZimBackupPath/$ZimBackupFile -C $ZimBackupPath tf zimbra_version.txt
-
 
206
 
-
 
207
  # Cleaning differential folder.
-
 
208
  rm -r -f $ZimDiffTmpPath/*
-
 
209
fi
-
 
210
}
-
 
211
 
189
 
212
diff_backup() {
190
  # Starting Zimbra
213
# Checking if LDAP database folder exist and fix it.
191
  zimbra_start
-
 
192
 
-
 
193
  # Compressing backup for space reduction
-
 
194
  tar -zcvpf $ZimBackupPath/$ZimBackupFile -C $ZimBackupPath tf zimbra_version.txt
-
 
Line 195... Line 214...
195
  
214
if [ ! -f "$ZimDiffTmpPath/$ZimHome/data/ldap/mdb/db/data.mdb" ];
196
  # Cleaning differential folder.
215
  then
197
   rm -r -f $ZimDiffTmpPath/*
216
    if [ ! -d "$ZimDiffTmpPath/$ZimHome/data/ldap/mdb/db" ]
198
fi
217
	  then
Line 199... Line 218...
199
}
218
        mkdir -p $ZimDiffTmpPath/$ZimHome/data/ldap/mdb/db
200
 
219
    fi
Line 201... Line 220...
201
diff_backup() {
220
else
202
if [ $ZimLogEnable = 'yes' ] && [ $ZimLogVerbose = 'yes' ]
221
  rm -R $ZimDiffTmpPath/$ZimHome/data/ldap/mdb/db/data.mdb
203
 then
222
fi
-
 
223
 
-
 
224
# Make backup
204
  # Cleaning backup folder
225
if [ $ZimLogEnable = 'yes' ] && [ $ZimLogVerbose = 'yes' ]
Line 205... Line 226...
205
  #echo "`date "+%Y-%m-%d %H:%M:%S"` - Cleaning backup folder..." >> $ZimLogFile
226
 then
206
  #rm -r -f $ZimDiffTmpPath/* >> $ZimLogFile
227
 
Line 207... Line -...
207
  #echo "`date "+%Y-%m-%d %H:%M:%S"` - Cleaning backup folder done." >> $ZimLogFile
-
 
208
 
-
 
209
  # Hot syncing to backup folder
-
 
210
  echo "`date "+%Y-%m-%d %H:%M:%S"` - Hot syncing to backup folder..." >> $ZimLogFile
-
 
211
  rsync -avHK --compare-dest=$ZimFullTmpPath/ $ZimInstPath/$ZimHome $ZimDiffTmpPath >> $ZimLogFile
-
 
212
  echo "`date "+%Y-%m-%d %H:%M:%S"` - Hot syncing to backup folder done." >> $ZimLogFile
228
  # Hot syncing to backup folder
213
 
229
  echo "`date "+%Y-%m-%d %H:%M:%S"` - Hot syncing to backup folder..." >> $ZimLogFile
214
  # Stopping Zimbra
230
  rsync -avHK --exclude 'data/ldap/mdb/db/data.mdb' --compare-dest=$ZimFullTmpPath/ $ZimInstPath/$ZimHome $ZimDiffTmpPath >> $ZimLogFile
215
  zimbra_stop
231
  echo "`date "+%Y-%m-%d %H:%M:%S"` - Hot syncing to backup folder done." >> $ZimLogFile
Line 216... Line 232...
216
 
232
 
Line 217... Line 233...
217
  # Cold syncing to backup folder
233
  # Stopping Zimbra
218
  echo "`date "+%Y-%m-%d %H:%M:%S"` - Cold syncing to backup folder..." >> $ZimLogFile
234
  zimbra_stop
219
  rsync -avHK --compare-dest=$ZimFullTmpPath/ $ZimInstPath/$ZimHome $ZimDiffTmpPath >> $ZimLogFile
235
 
Line 220... Line 236...
220
  echo "`date "+%Y-%m-%d %H:%M:%S"` - Cold syncing to backup folder done." >> $ZimLogFile
236
  # Cold syncing to backup folder
221
 
237
  echo "`date "+%Y-%m-%d %H:%M:%S"` - Cold syncing to backup folder..." >> $ZimLogFile
Line 222... Line 238...
222
  # Starting Zimbra
238
  rsync -avHK --exclude 'data/ldap/mdb/db/data.mdb' --compare-dest=$ZimFullTmpPath/ $ZimInstPath/$ZimHome $ZimDiffTmpPath >> $ZimLogFile
223
  zimbra_start
239
  # Special LDAP DB copying needed.
224
 
-
 
-
 
240
  $ZimInstPath/$ZimHome/openldap/bin/mdb_copy $ZimInstPath/$ZimHome/data/ldap/mdb/db $ZimDiffTmpPath/$ZimHome/data/ldap/mdb/db >> $ZimLogFile
-
 
241
  echo "`date "+%Y-%m-%d %H:%M:%S"` - Cold syncing to backup folder done." >> $ZimLogFile
225
  # Syncing backup folders
242
 
226
  #echo "`date "+%Y-%m-%d %H:%M:%S"` - Syncing backup folders..." >> $ZimLogFile
243
  # Starting Zimbra
Line 227... Line -...
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
244
  zimbra_start
231
  echo "`date "+%Y-%m-%d %H:%M:%S"` - Compressing backup folder..." >> $ZimLogFile
245
 
232
  tar -zcvpf $ZimBackupPath/$ZimBackupFile -C $ZimBackupPath td zimbra_version.txt >> $ZimLogFile
246
  # Compressing backup folder
233
  echo "`date "+%Y-%m-%d %H:%M:%S"` - Compressing backup folder done." >> $ZimLogFile
247
  echo "`date "+%Y-%m-%d %H:%M:%S"` - Compressing backup folder..." >> $ZimLogFile
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
Line 273... Line 287...
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
Line 276... Line 290...
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
Line 557... Line 571...
557
  sleep 10
571
  sleep 10
Line 558... Line 572...
558
 
572
 
559
fi
573
fi
Line 560... Line -...
560
}
-
 
561
 
-
 
562
full_restore() {
-
 
563
echo "Full Restore under development"
-
 
564
}
-
 
565
 
-
 
566
diff_restore() {
-
 
567
echo "Diff Restore under development"
-
 
568
}
574
}
569
 
575
 
Line 570... Line 576...
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