Zimbra offers Open Source email server software and shared calendar for Linux and the Mac
Go Back   Zimbra :: Forums > Zimbra Collaboration Suite > Administrators

Welcome to the Zimbra :: Forums!
Welcome, if you would like to post a comment please register. We also encourage you to explore all things Zimbra with our team and members of the community.

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 03-03-2008, 04:05 AM
Active Member
 
Posts: 47
Default Simple backup script for OSE version

I have made some overhaulin of my script and added file transfer functions, read below. The script can be downloaded <Here> for convenience.

If any errors are found in the script post here and i will look into it right away.

/Soulskater

Changes as of 2008-03-08:
-------------------------------------
for those of you who have been using this script re-download the code since there has been some bug fixes, non critical but still.

Following bug has been fixed:
When running the msg option it created a extra folder called 0 in backup dir/store which resulted in double 0 folders in backup folder, ex,
backdir/store/0/0 should have been backupdir/store/0.

have been expirence some issues in ubuntu when running the script via crontab, though it is not limited to this script but rather an issue with the packaging with tar option, if you are running this script in crontab add following at the end of each line where you call this script, > /dev/nul 2>&1l ex.
0 23 * * * /opt/scripts/ZimBackup.sh full > /dev/null 2>&1

Changes as of 2008-03-09:
-------------------------------------
- Fixed issues with this script when running from crontab
- added more backup options.

Changes as of 2008-04-18:
-------------------------------------
Script has been updated with new functionality that enables file transfer with ftp & scp protocols.
__________________
Systems Specialist
openSUSE Ambassador in Sweden
Visit my blogs at www.osource.se

Last edited by soulskater; 04-18-2008 at 06:51 AM..
Reply With Quote
  #2 (permalink)  
Old 03-03-2008, 06:08 AM
Zimbra Consultant & Moderator
 
Posts: 19,621
Default

Quote:
Originally Posted by soulskater View Post
Just made a script for backing up my OSE version of Zimbra and thought to share it with those who might want it. Have seen a couple of script popping up in the forum with backup scripts and wanted to share mine to.
Another one, the more the merrier.

Thanks for writing the script and posting it here, would you mind putting a copy of it on the wiki in the Backup & Restore section?
__________________
Regards


Bill
Reply With Quote
  #3 (permalink)  
Old 03-03-2008, 06:36 AM
Active Member
 
Posts: 47
Default

Thanks.

Sure i will put it in the wiki, just have to figure out how.
__________________
Systems Specialist
openSUSE Ambassador in Sweden
Visit my blogs at www.osource.se
Reply With Quote
  #4 (permalink)  
Old 03-09-2008, 04:31 AM
Active Member
 
Posts: 47
Default

Script has now been updated, see first post for latest version.
__________________
Systems Specialist
openSUSE Ambassador in Sweden
Visit my blogs at www.osource.se
Reply With Quote
  #5 (permalink)  
Old 03-09-2008, 06:51 AM
Active Member
 
Posts: 47
Default

Another update, now the script should be ready for the wiki, will post when it is there.
__________________
Systems Specialist
openSUSE Ambassador in Sweden
Visit my blogs at www.osource.se
Reply With Quote
  #6 (permalink)  
Old 03-11-2008, 03:42 PM
Loyal Member
 
Posts: 80
Default ssh rsync

I want to rsync resulting file/s should did I modify the the script properly?
code is toward the bottom. I have the remote computer set up for automatic ssh authentication.


Code:
#!/bin/bash

# This script will do various backups of Zimbra depending on wich you choose,
# most of them are cold backups except the msg backup wich hot copies the 'store'
# folder for possible individual mail retrival. Be sure to change the variables below
# to point to where you got the zimbra folder and where you want it to be backed up to.
#
# This script must be run as root or a user with equal privileges or it will not work.
#
# Usage: ZimBackup.sh full	- For full backup (Cold)
#	 ZimBackup.sh diff	- For diffrential backup (Cold)
#	 ZimBackup.sh msgfull	- For complete message backup (Hot)
#	 ZimBackup.sh msgdiff	- For diffrential message backup (Hot)
#
# When you run this script via crontab be sure to add '> /dev/null 2>&1' at the end
# of the script like below or the tar command will fail for no apparent reason.
# 00 12 * * * ZimBackup.sh full > /dev/null 2>&1
#
# Bits and pieces was adopted from a script created by Daniel W. Martin, 9 Sept 2007
# Free to use and free of any warranty!  Marcus Uddenhed, 3 feb 2008
#
# Last updated: 2008-03-09

ZimInstPath=/opt
ZimHome=zimbra
ZimBackupPath=/opt/backup
ZimTempPath=/opt/backup/tmp

# Do not change anything below this line unless you know what you are doing

pre_check() {
# Check to see if the tmp folder exist, and create if not
mkdir -p $ZimTempPath

# Check which zimbra version that is installed, for recovery purpose 
sudo -u zimbra $ZimInstPath/$ZimHome/bin/zmcontrol -v > $ZimTempPath/zimbra_version.txt
}

full_backup() {
# Removing possible old zimbra backup folder
rm -r -f $ZimTempPath/$ZimHome

# Stopping Zimbra
/etc/init.d/zimbra stop
sleep 20

# Backing up zimbra folder
cp -rv $ZimInstPath/$ZimHome $ZimTempPath/

# Starting Zimbra
/etc/init.d/zimbra start

# Compressing backup for space reduction
tar -zcvf $ZimBackupPath/ZimBackupTypeFull_`date +%Y%m%d%H%M`.tar.gz -C $ZimTempPath $ZimHome zimbra_version.txt
}

diff_backup() {
# Hot sync before shutdown on zimbra folder
rsync -avHK --delete $ZimInstPath/$ZimHome $ZimTempPath/

# Stopping Zimbra
/etc/init.d/zimbra stop
sleep 20

# Cold sync of zimbra folder
rsync -avHK --delete $ZimInstPath/$ZimHome $ZimTempPath/

# Starting Zimbra
/etc/init.d/zimbra start

# Compressing backup for space reduction and removing unpacked folder
tar -zcvf $ZimBackupPath/ZimBackupTypeDiff_`date +%Y%m%d%H%M`.tar.gz -C $ZimTempPath $ZimHome zimbra_version.txt
}

msgfull_backup() {
# Removing possible old store backup folder
rm -r -f $ZimTempPath/store

# Make dir for hot sync
mkdir -p $ZimTempPath/store

# Hot sync of mailbox messages
rsync -avHK --delete $ZimInstPath/$ZimHome/store/0 $ZimTempPath/store/

# Compressing store folder for space reduction
tar -zcvf $ZimBackupPath/ZimBackupTypeMsg_`date +%Y%m%d%H%M`.tar.gz -C $ZimTempPath store zimbra_version.txt
}

msgdiff_backup() {
# Make dir for hot sync
mkdir -p $ZimTempPath/store

# Hot sync of mailbox messages
rsync -avHK --delete $ZimInstPath/$ZimHome/store/0 $ZimTempPath/store/

# Compressing store folder for space reduction
cd $ZimTempPath
tar -zcvf $ZimBackupPath/ZimBackupTypeMsg_`date +%Y%m%d%H%M`.tar.gz -C $ZimTempPath store zimbra_version.txt
}

################################
rsync -e ssh -varuzP $ZimBackupPath/ remotemachine:/backup
################################

case $1 in
full)
pre_check
full_backup
;;
diff)
pre_check
diff_backup
;;
msgfull)
pre_check
msgfull_backup
;;
msgdiff)
pre_check
msgdiff_backup
;;
*)
echo "Usage: ZimColdBackup.sh {full|diff|msgfull|msgdiff}"
;;
esac
Reply With Quote
  #7 (permalink)  
Old 03-11-2008, 05:13 PM
Moderator
 
Posts: 1,027
Exclamation Vote on FOSS hot backups

Anyone interested in seeing backup options improve should vote on this poll initiated by Zimbra:

Vote: Hot Backups for FOSS?

Dan
Reply With Quote
  #8 (permalink)  
Old 03-12-2008, 04:33 AM
Active Member
 
Posts: 47
Default

Hi.

Have tried you command with slightly changed parameters, only minor and it looks like it works, below is my line as a tested it from the console directly.

rsync -e ssh -varuzP /opt/backup/ user@server:/destinationfolder/

The diffrence is that i put a username to the line and can't see one in yours, can be due to editing the script for insertion here...

Have you tried the script?
__________________
Systems Specialist
openSUSE Ambassador in Sweden
Visit my blogs at www.osource.se
Reply With Quote
  #9 (permalink)  
Old 03-12-2008, 04:39 AM
Moderator
 
Posts: 7,911
Default

If the same user, as the one performing the backup job, is on the remote server and the keys have been exchanged then a specified user should not be required.

I second dwmtractor's comment, please vote on the FOSS backup poll
__________________
Reply With Quote
  #10 (permalink)  
Old 03-12-2008, 04:47 AM
Active Member
 
Posts: 47
Default

True, but that was not the case in my enviorment.

/soulskater
__________________
Systems Specialist
openSUSE Ambassador in Sweden
Visit my blogs at www.osource.se
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes


Similar Threads

Why Join?

Registering let's you ask questions, makes it easier to search, displays any files attached to posts, and notifies you about replies.

blog.zimbra.com




 

SEO by vBSEO ©2011, Crawlability, Inc.