+=item backupkoha
+
+ backupkoha;
+
+This function attempts to back up all koha's details.
+
+=cut
+
+$messages->{'BackupDir'}->{en} = heading('BACKUP STORAGE').qq|
+The upgrader will now try to backup your old files.
+
+Please specify a directory to store the backup in [%s]: |;
+
+$messages->{'BackupSummary'}->{en} = heading('BACKUP SUMMARY').qq|
+Backed up:
+
+%6d biblio entries
+%6d biblioitems entries
+%6d items entries
+%6d borrowers
+
+File Listing
+---------------------------------------------------------------------
+%s
+---------------------------------------------------------------------
+
+Does this look right? ([Y]/N): |;
+
+#FIXME: rewrite to use Install.pm
+sub backupkoha {
+my $backupdir=$ENV{'prefix'}.'/backups';
+
+my $answer = showmessage(getmessage('BackupDir',[$backupdir]),'free',$backupdir);
+
+if (! -e $backupdir) {
+ my $result=mkdir ($backupdir, oct(770));
+ if ($result==0) {
+ my @dirs = split(m#/#, $backupdir);
+ my $checkdir='';
+ foreach (@dirs) {
+ $checkdir.="$_/";
+ unless (-e "$checkdir") {
+ mkdir($checkdir, 0775);
+ }
+ }
+ }
+}
+
+chmod 0770, $backupdir;
+
+# Backup MySql database
+#
+#
+my $mysqldir = getmysqldir();
+
+my ($sec, $min, $hr, $day, $month, $year) = (localtime(time))[0,1,2,3,4,5];
+$month++;
+$year+=1900;
+my $date= sprintf "%4d-%02d-%02d_%02d:%02d:%02d", $year, $month, $day,$hr,$min,$sec;
+
+open (MD, "$mysqldir/bin/mysqldump --user=$user --password=$pass --host=$hostname $database|");
+
+(open BF, ">$backupdir/Koha.backup_$date") || (die "Error opening up backup file $backupdir/Koha.backup_$date: $!\n");
+
+my $itemcounter=0;
+my $bibliocounter=0;
+my $biblioitemcounter=0;
+my $membercounter=0;
+
+while (<MD>) {
+ (/insert into items /i) && ($itemcounter++);
+ (/insert into biblioitems /i) && ($biblioitemcounter++);
+ (/insert into biblio /i) && ($bibliocounter++);
+ (/insert into borrowers /i) && ($membercounter++);
+ print BF $_;
+}
+
+close BF;
+close MD;
+
+my $filels=`ls -hl $backupdir/Koha.backup_$date`;
+chomp $filels;
+$answer = showmessage(getmessage('BackupSummary',[$bibliocounter, $biblioitemcounter, $itemcounter, $membercounter, $filels]),'yn');
+
+if ($answer=~/^n/i) {
+ print qq|
+
+Aborting. The database dump is located in:
+
+ $backupdir/Koha.backup_$date
+
+|;
+ exit;
+} else {
+ print "Great! continuing upgrade... \n";
+};
+
+
+
+}