Posted by: David | October 23, 2010

Citadel Online ("Hot") Backup : Script

So as previously mentioned, I use the Citadel Server as my email / groupware server, and like all good admins I like a backup, when I put the server in this was one of the first things I sorted out. I checked the Citadel Manual for their suggestions on backing up the server. Their manual offers two backup methods; online and offline. Now I am not a great fan of offline backups, nor do I see the point, if you are going to have a server why should you have to take it offline to back it up? So online backup it is then.

There are a couple of things to note here:

  1. You cannot have automatic deletion of logs enabled in Citadel if you use this method (this is done under side wide configuration in webcit when logged in with the Admin account)
  2. You must make sure that you backup the database and log files in the correct order otherwise no restore for you…

So the script, now I am not overly familiar with Shell Scripting so I am sure there will be some of you out there that look at this script and neatly reduce it to 5 lines of code, if you do please let me know you secrets!
#!/bin/bash
backuplocation="/backup/"
suffix=citbackup
prefix=$(date +%Y%m%d)
filename=$suffix
echo $filename

#re-create file citadel directory structure in backup location
mkdir $backuplocation$filename
mkdir $backuplocation$filename/bio
mkdir $backuplocation$filename/bitbucket
mkdir $backuplocation$filename/files
mkdir $backuplocation$filename/images
mkdir $backuplocation$filename/info
mkdir $backuplocation$filename/keys
mkdir $backuplocation$filename/userpics
mkdir $backuplocation$filename/data

#copy files as per citadel reccomendations
cp /var/lib/citadel/* $backuplocation$filename/
cp -Rv /var/lib/citadel/bio $backuplocation$filename/bio
cp -Rv /var/lib/citadel/bitbucket $backuplocation$filename/bitbucket
cp -Rv /var/lib/citadel/files $backuplocation$filename/files
cp -Rv /var/lib/citadel/images $backuplocation$filename/images
cp -Rv /var/lib/citadel/info $backuplocation$filename/info
cp -Rv /var/lib/citadel/keys $backuplocation$filename/keys
cp -Rv /var/lib/citadel/userpics $backuplocation$filename/userpics
cp -v /var/lib/citadel/data/cdb.* $backuplocation$filename/data/
cp -v /var/lib/citadel/data/log.* $backuplocation$filename/data/
cp -v /var/lib/citadel/data/ref* $backuplocation$filename/data/

#Compress Backup Files
rm $backuplocation$filename.tar.gz
tar -pczf $backuplocation$filename.tar.gz $backuplocation$filename

rm -R $backuplocation$filename

#Delete undeeded logs from Citadel
echo "Culling logs"
/usr/sbin/sendcommand "CULL"

So there are a couple of things that you need to check here, all the locations are set at the top of the script, and you may also want to check where the sendcommand command is located on your system, I installed my server with apt-get but I know that some of the other provided utilities (ctdlmigrate being one) did not work for me because they were looking somewhere else for the sendcommand command. It is important that you make sure this is correct as it is this line of the script which clears out the logs from the server once the backup is taken. If you don’t clear out these logs you may find after a while you begin to run out of disk space.

The script needs to be run under the citadel user account so that it has permissions to access and backup the citadel database files, I cheated with this and used Webmin to configure my scheduled backup in cron.

However if you create a file called your citadel username (e.g. citadel) with the contents below in /var/spool/cron/crontabs this should do the trick.
0 3 * * * sh /var/lib/citadel/backup
The only other thing you should be aware of is that the citadel user needs permission to write to the backup location, here are the permissions I have set on the backup directory
drwxrwxr-x 2 root citadel 4096 Oct 23 16:37 backup
With regards to restore, it should be noted that this data will only be re-storable if the system has the same architecture i.e 32-bit or 64-bit. But I have tested this (accidentally deleted some emails I needed), to do a restore simply install citadel on a machine, stop all the Citadel services and then copy the data from the backup to the Citadel folder, start the services and log in with your old admin account details.

If you do want to do a “cold” or offline backup where you shut the citadel services down, instructions on how to do so can be found on postfixmail.com

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Categories

%d bloggers like this: