Koozali.org: home of the SME Server

e-mail backups

Bob Jenner

e-mail backups
« on: January 11, 2003, 03:58:07 AM »
Hello all,
I have an interesting request I am hoping someone can help me with.

I have a client that uses SME (5.5 sp2) as their firewall and email server. They want to be able to create a backup file (tar?) of each users email (clients are setup for IMAP so all email remains on the server and is accessible by webmail).

I would like to create a script to be run by cron to autocreate a seperate email backup file per user (to make sure I don't exceed the 2GB file size limit). I have done this already, but only a single file for all users.

How can I setup the script to traverse the directory and create a seperate tar file for each users directory, then copy them to /mnt/smb/Mailbackups/ which is a SMB mount of a W2k server with a tape drive.

I hope this is clear enough. If anyone has questions, please email me directly at
bjenner@tndi.net.

Thank you all,

Bob

Nathan Fowler

Re: e-mail backups
« Reply #1 on: January 11, 2003, 06:28:31 AM »
Good idea, here is the script you want, I just wrote it because I figured I could use it too :)  I've not done a great deal of testing, so if you encounter any bugs let me know.  Note that none of the lines should wrap, if they wrap on the screen be sure to fix that.

Just slap this in /etc/cron.weekly or /etc/cron.daily and be sure to chmod +x the file.

Please let me know if you encounter any bugs.

#!/usr/bin/perl
#/* Nathan Fowler
# * evilghost@stickit.nu
# * January 10, 2003
# * Backup the users directory into a single tar-ball.
# * Support auto-cleaning after 7 days.
# */

#//////////////////////////////////////////
#// Edit these values to suit your needs //
#//////////////////////////////////////////
  #Path to save backups to.
  $backup_directory = "/tmp/backup";

  #Backup Files in this directory
  $source_directory = "/home/e-smith/files/users";

  #Path to GNU-tar
  $path_to_tar = "/bin/tar";

  #Remove files after 7 days.  This is 7 days, in seconds.
  $expired_date = 604800;

  #Logfile name
  $logfile = "/var/log/user_backup.log";

#/////////////////////////////////////////////
#// Not necessary to edit beyond this line. //
#/////////////////////////////////////////////

use File::stat;
$date = localtime();

#Create directories as necessary
mkdir $backup_directory;

#// Open the logfile
open(LOG,">>$logfile") || die("Can't open $logfile");

#// Find and remove expired backups.
@backup_files = ls $backup_directory/*.tgz;
foreach $backup_file (@backup_files) {
  chop($backup_file);
  $file = $backup_file;
  $s = stat($file) || die "Can't stat($file) $!\n";
  $now = time;
  $modtime = $s->mtime + $expired_date;
  if($modtime < $now){
    $date = localtime();
    unlink($backup_directory . "/" . $backup_file);
    print "$date - Removed $backup_file from $backup_directory\n";
    print LOG "$date - Removed $backup_file from $backup_directory\n";
  }
}
 
#// Initiate the backup
@userdirs = ls -D $source_directory;
foreach $userdir (@userdirs) {
  chop($userdir);
  $tgz = "$path_to_tar --directory=\"" . $source_directory . "\" --create --gzip --file=\"". $backup_directory . "/" . $userdir . "_" . time . ".tgz\" " . $userdir;
  $tgz;
  print "$date - Backed up $userdir to $backup_directory\n";  
  print LOG "$date - Backed up $userdir to $backup_directory\n";  
}

close(LOG);
exit;

Nathan Fowler

Re: e-mail backups
« Reply #2 on: January 11, 2003, 06:29:40 AM »
Found a bug, change:
    unlink($backup_directory . "/" . $backup_file);

To:
    unlink($backup_file);

Bill Talcott

Re: e-mail backups
« Reply #3 on: January 13, 2003, 09:18:34 PM »
FYI, the User Manager panel addon gives each user the ability to back up their own data (as well as lots of other useful stuff).

JBaker

Re: e-mail backups
« Reply #4 on: January 29, 2003, 07:50:03 PM »
installed the User Manager panel addon  but only have options
for changing password and/or email delivery (fwd/local/both)

where is/are the backup option(s)? is there a later version of this that gives these options (my rpm =
e-smith-userpanel-pkg-0.0.1-1.noarch.rpm)

Thanks

-John-