LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 03-19-2014, 01:23 AM   #1
pople
LQ Newbie
 
Registered: Nov 2013
Distribution: Gentoo
Posts: 26

Rep: Reputation: Disabled
Zimbra Backup Script


I wrote a script to back up a zimbra server content and works better than others I have seen. It does a few extra things like check to see if the drive is mounted, see if the drive is full, sets up a log file in home dir, and reschedules itself using at. Here it is:
Code:
#!/bin/bash

currentdate=$(date)
mount | grep /dev/sdb1 > /dev/null
   if [ "$?" -eq "0" ]; then
        echo "/dev/sdb1 is mounted"
	DISKSPACE=`df -H /dev/sdb1 | sed '1d' | awk '{print $5}' | cut -d'%' -f1`
	if [ $DISKSPACE -lt '95' ]; then 
	   su - zimbra -c "zmcontrol shutdown"
	    echo "Copying backup on $currentdate"
	    cp -rp /opt/zimbra /media/sdb1/`date +%y%m%d`/
	    echo "Backup made on $currentdate" >> $HOME/zimbra_backup.log
	else
	    echo "No Backup made on $currentdate disk full" >> $HOME/zimbra_backup.log
	    exit 1
	fi 
   else
        echo "/dev/sbd1 is not mounted at this time."
	echo "No Backup made on $currentdate no disk mounted" >> $HOME/zimbra_backup.log
   fi
echo "$HOME/zimbra_backup.sh" | at 3am + 1 days 
su - zimbra -c "zmcontrol startup"
Btw the reason I did not use services it becuase all the services script /etc/init.d/zimbra does is call zmcontrol. To use this one would just sudo ./<the script>.sh. Hopes this saves someone the trouble in the future.
 
Old 07-31-2014, 04:13 AM   #2
jerrybu01
LQ Newbie
 
Registered: Mar 2014
Posts: 5

Rep: Reputation: Disabled
Quote:
Originally Posted by pople View Post
I wrote a script to back up a zimbra server content and works better than others I have seen. It does a few extra things like check to see if the drive is mounted, see if the drive is full, sets up a log file in home dir, and reschedules itself using at. Here it is:
Code:
#!/bin/bash

currentdate=$(date)
mount | grep /dev/sdb1 > /dev/null
   if [ "$?" -eq "0" ]; then
        echo "/dev/sdb1 is mounted"
	DISKSPACE=`df -H /dev/sdb1 | sed '1d' | awk '{print $5}' | cut -d'%' -f1`
	if [ $DISKSPACE -lt '95' ]; then 
	   su - zimbra -c "zmcontrol shutdown"
	    echo "Copying backup on $currentdate"
	    cp -rp /opt/zimbra /media/sdb1/`date +%y%m%d`/
	    echo "Backup made on $currentdate" >> $HOME/zimbra_backup.log
	else
	    echo "No Backup made on $currentdate disk full" >> $HOME/zimbra_backup.log
	    exit 1
	fi 
   else
        echo "/dev/sbd1 is not mounted at this time."
	echo "No Backup made on $currentdate no disk mounted" >> $HOME/zimbra_backup.log
   fi
echo "$HOME/zimbra_backup.sh" | at 3am + 1 days 
su - zimbra -c "zmcontrol startup"
Btw the reason I did not use services it becuase all the services script /etc/init.d/zimbra does is call zmcontrol. To use this one would just sudo ./<the script>.sh. Hopes this saves someone the trouble in the future.
Now, i want to restore a new backupfile, how can i run script?
 
Old 07-31-2014, 12:51 PM   #3
Habitual
LQ Veteran
 
Registered: Jan 2011
Location: Abingdon, VA
Distribution: Catalina
Posts: 9,374
Blog Entries: 37

Rep: Reputation: Disabled
Not sure if this was rhetorical or not, but if I ran this script, and needed a restore, I'd check contents of
/media/sdb1/`date +%y%m%d`


where date +%y%m%d is the day in question.
 
Old 08-07-2014, 03:46 PM   #4
pople
LQ Newbie
 
Registered: Nov 2013
Distribution: Gentoo
Posts: 26

Original Poster
Rep: Reputation: Disabled
Yep. You would need to check the directory /media/sdb1 for the latest backup. If you wanted to restore a backup you would need to do the following. In root:

Make sure you want to delete your existing zimbra folder before running the backup.
Code:
rm -rf /opt/zimbra/
cp -r /media/sdb1/<date> /opt/zimbra/
After you have copied the backup to the home directory for zimbra you will need to change permissions.
Code:
chown zimbra:zimbra /opt/zimbra -R
I think this should work. It has been a while since I have done this. After chaing permissions. Restart zimbra.

Code:
su - zimbra -c "zmcontrol startup"
 
Old 08-08-2014, 01:20 PM   #5
pople
LQ Newbie
 
Registered: Nov 2013
Distribution: Gentoo
Posts: 26

Original Poster
Rep: Reputation: Disabled
Here is an updated script. This will do the same thing as before except add compression putting the backups in tarballs. It will also email the admin to notify him/her that a backup has been made or not made.

Code:
#!/bin/bash

currentdate=$(date)
mount | grep /dev/sdb1 > /dev/null
   if [ "$?" -eq "0" ]; then
        echo "/dev/sdb1 is mounted"
        DISKSPACE=`df -H /dev/sdb1 | sed '1d' | awk '{print $5}' | cut -d'%' -f1`
        if [ $DISKSPACE -lt '95' ]; then 
           su - zimbra -c "zmcontrol shutdown"
            echo "Copying backup on $currentdate"
            cp -rp /opt/zimbra /media/sdb1/`date +%y%m%d`/
            tar cfJ /media/sdb1/`date +%y%m%d`.tar.xz /media/sdb1/`date +%y%m%d` && rm -rf /media/sdb1/`date +%y%m%d`
            echo "Backup made on $currentdate" >> $HOME/zimbra_backup.log
        else
            echo "No Backup made on $currentdate disk full" >> $HOME/zimbra_backup.log
            exit 1
        fi 
   else
        echo "/dev/sbd1 is not mounted at this time."
        echo "No Backup made on $currentdate no disk mounted" >> $HOME/zimbra_backup.log
   fi
echo "$HOME/zimbra_backup.sh" | at 3am + 1 days 
su - zimbra -c "zmcontrol startup"
cat /opt/zimbra/zimbra_backup.log | /opt/zimbra/postfix/sbin/sendmail mail@domain.org

Last edited by pople; 08-08-2014 at 02:49 PM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Need Shell Script to parse Zimbra Sync.log rlug Linux - General 1 01-08-2012 08:29 AM
Newbie trying to write a simple backup script to backup a single folder Nd for school stryker759a Linux - Newbie 2 09-16-2009 08:52 AM
zimbra backup saran_redhat Linux - Server 1 06-24-2009 11:24 AM
how to create backup MYSQL Script to backup my database for every 1hour RMLinux Linux - Newbie 3 11-20-2008 10:13 AM
LXer: Zimbra Goes Offline With Zimbra Desktop LXer Syndicated Linux News 0 03-28-2007 12:16 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 10:49 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration