This is what I did, and experimented with one account in Zimbra. It worked well. But don't know if it is technically correct to do so.
Code:
#!/usr/bin/perl
use POSIX;
# You can change the below given three directories to point to relevant directories on your system
# DO NOT FORGET to put a trailing "/" after the directory names, else the results wont be good!
# This is where Zimbra is installed.
my $zimbra_src = "/opt/zimbra/";
# This is where it needs to be synced.
my $zimbra_synced = "/opt/zimbra_synced/";
# This is where the snapshots are stored.
my $zimbra_snaps = "/opt/zimbra_snaps/";
######################### Please dont change anything below this line #########################
my $introduction = qq[
This script will:
Step 1. Put the entire running instance of Zimbra under maintenance mode. During the maintenance mode all users will have Read-Only access.
Step 2. Sync the contents of $zimbra_src to $zimbra_synced directory.
Step 3. Change Zimbra's mode from maintenance to active.
Step 4. Create a gzipped tarball, as a snapshot from the contents of Synced directory and store it in $zimbra_snaps.
Warning:
1. This script can take a lot of time depending upon the size of your Zimbra directory. Please do not interrupt it in the process.
Advice:
It is preferred that you run this script as \"nohup zimbra_backup &\" or run it using cron. This way the process of backup will not be interrupted.
];
print $introduction;
# Check if the directories mentioned above exist
if (!(-e $zimbra_src)) {
print "Oops! You specified the wrong Zimbra directory.\n";
exit;
}
if (!(-e $zimbra_synced)) {
print "The directory Syncing that you have specified does not exist. So, creating $zimbra_synced ...\n";
mkdir ($zimbra_synced, 0700);
}
if (!(-e $zimbra_snaps)) {
print "The directory for storing snapshots that you have specified does not exist. So, creating $zimbra_snaps ...\n";
mkdir ($zimbra_snaps, 0700);
}
my $cmd_maintenance = "sudo -u zimbra /opt/zimbra/bin/zmcontrol maintenance";
# Changing to maintenance mode
print "Now, Changing to maintenance mode ... (READ-ONLY MODE ENABLED)\n";
system($cmd_maintenance);
# Using rsync for syncing
my $cmd_rsync = "rsync -av $zimbra_src $zimbra_synced";
print "Now, Using rsync to sync the data...\n";
system($cmd_rsync);
# Going out of maintenance mode
print "Now, Changing out from maintenance mode ... (NORMAL MODE ENABLED)\n";
system($cmd_maintenance);
# Get the date and time
$ENV{TZ} = ':/usr/share/zoneinfo/Asia/Calcutta';
my $current_date_time = POSIX::strftime('%Y-%B-%d-%H-%M-%S', localtime(time));
# Create filename for gzipped tarball
my $targz_filename = "zmbak-$current_date_time.tar.gz";
$targz_filename = "$zimbra_snaps"."$targz_filename";
my $cmd_gztar = "tar -Pcvzf $targz_filename $zimbra_synced";
print "Now, Creating a gzipped tarball from the synced directory ...\n";
system($cmd_gztar);
print "Done! Thank-you for using this script!\n"; I am editing this post because I think it will be good to explain what the script above does:
This script will:
Step 1. Put the entire running instance of Zimbra under maintenance mode. During the maintenance mode all users will have Read-Only access.
Step 2. Sync the contents of /opt/zimbra to /opt/zimbra_synced directory.
Step 3. Change Zimbra's mode from maintenance to active.
Step 4. Create a gzipped tarball, as a snapshot from the contents of Synced directory and store it in /opt/zimbra_snaps.
Is this logically, Ok?
Thank-you,
Sincerely,
Chintan Zaveri.