[Home]EmailBackupWiki

UseModWiki | RecentChanges | Preferences

This script EmailBackupWiki creates a tar.gz-file from a specified directory and sends it per email.

You have to adapt the variables in the configuration-section.

Cronjob: You can automate your backups with the help of a cron-server, e.g. http://www.webcron.org.

--BernhardZechmann

Please feel free to delete this comment if it's out of place, but I wanted to say a big thankyou for this script - being an utter Perl novice, I was worried about not having backups of [my wiki], but this looks like just the solution I was hoping for. --Mutt


#!/usr/bin/perl
#
# EmailBackupWiki version 1.0 (February 19, 2004)
# Copyright (C) 2004 Bernhard Zechmann
# <http://www.zechmann.com> or <http://www.2plm.com>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You can receive a copy of the GNU General Public License here:
#    Free Software Foundation, Inc.
#    59 Temple Place, Suite 330
#    Boston, MA 02111-1307 USA
#    http://www.gnu.org
#

# Path for Perl libs and modules
use Socket;
use MIME::Entity;


# == Configuration =====================================================
$website_url         ="http://www.2plm.de";               # url to your website
$path_to_backupfile  ="/home/....";                       # where is the backupfile stored temporary
$path_for_backup     ="/home/..../mywikidb";              # which path has to be packed and zipped
$mailprog            ="/usr/sbin/sendmail";               # mailprogram with path
$mail_from           ="backup\@server.com";               # email from 
$mail_to             ="receiver\@home.com";               # email-address where the backupfile is sent to
$mail_subject        ="Backup from wiki-webserver - ";    # subject of the backup-mail
# == End of Configuration ==============================================


# == Configuration/constant variables ==================================
my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) = localtime(); $pid=$$;
$year = $year + 1900;
$mon = $mon + 1;
if (length($mon)  == 1) {$mon = "0$mon";}
if (length($mday) == 1) {$mday = "0$mday";}
if (length($hour) == 1) {$hour = "0$hour";}
if (length($min)  == 1) {$min = "0$min";}
if (length($sec)  == 1) {$sec = "0$sec";}
$File = "$path_to_backupfile/backupwiki_$year$mon$mday$hour$min.tar.gz"; #change this to your data file
# == End of Configuration/constant variables ===========================


# == The "main" program ================================================

print "Content-type: text/html\n\n";
system("tar -zcf $File $path_for_backup");
print "<html><head><title>Backup wiki</title>\n</head><body><font face=\"Verdana\" size=\"2\" color=\"#008000\">
    The wiki backup has started.<br>
    The tarball file is sent by email.<br>
    <br><br>
    <hr>
    Click <a href=\"$website_url\">here</a> to navigate to the website.</body>";
&sendemail;


# == Common code =======================================================

sub sendemail {
  local($print_config,$key,$sort_order,$sorted_field,$env_report);
  $auto_type = 'text/plain';
  $auto_encoding = 'base64';
  $auto_body = 'body.txt';
  $message_type = 'multipart/mixed';
  $log_or_email = 'B';
  $Body="Guess what";
  $top = build MIME::Entity Type => $message_type,
                            From => $mail_from,
                              To => $mail_to,
                         Subject => "$mail_subject $year$mon$mday$hour$min";
  attach $top Data=> $Body;
  attach $top Path => "$File",Type => $auto_type,Encoding => $auto_encoding;
  open MAIL, "|$mailprog -t -i" or die "open: $!";
    $top->print(\*MAIL);
  close MAIL;
  my @file ="$File"; #comment these out if you go ahead with your file
  unlink @file; # and this one
}


# == End ===============================================================


UseModWiki | RecentChanges | Preferences
Edit text of this page | View other revisions | Search MetaWiki
Last edited March 13, 2005 4:49 pm by 189.31.224.fdial.global.net.uk (diff)
Search: