initial commit of file from CVS for e-smith-flexbackup on Wed 12 Jul 08:54:20 BST 2023

This commit is contained in:
Brian Read
2023-07-12 08:54:20 +01:00
parent 774ef452c7
commit 4a4231dda8
41 changed files with 1615 additions and 2 deletions

View File

@@ -0,0 +1 @@
32

View File

@@ -0,0 +1 @@
20

View File

@@ -0,0 +1 @@
buffer

View File

@@ -0,0 +1 @@
tar

View File

@@ -0,0 +1 @@
backupservice

View File

@@ -0,0 +1,4 @@
#! /bin/sh
cd /
exec /usr/bin/flexbackup -set all -noreten

View File

@@ -0,0 +1,327 @@
#!/usr/bin/perl -w
#----------------------------------------------------------------------
# copyright (C) 1999-2005 Mitel Networks Corporation
#
# 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 should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
#----------------------------------------------------------------------
# Restore e-smith config etc from tape using flexbackup
package esmith;
use esmith::ConfigDB;
use esmith::Backup;
use strict;
my $conf = esmith::ConfigDB->open_ro or die "Could not open config db";
my $backup_program = $conf->get('backup')->prop('Program');
unless (defined $backup_program && $backup_program eq 'flexbackup')
{
exit(0);
}
package main;
###########################################################################
use POSIX;
use English;
use strict;
my $configfile = "/etc/flexbackup.conf";
my $filesystem = "/";
my $tempfile = "/tmp/restore.$$";
my $backup = new esmith::Backup or die "Couldn't create Backup object\n";
my @restore = $backup->restore_list;
package cfg;
require $configfile;
@cfg::filesystems = split(/ /, $cfg::set{full});
package main;
sub FindTapeFile ($);
sub ProbeTape ($);
sub RewindTape ($);
sub FSFTape ($$);
sub DetermineBlocksize($);
sub CreateFileList($);
sub ExtractFiles($$$);
sub NotifyAdmin ($$);
sub DetermineBackupType;
unless (defined @cfg::filesystems && @cfg::filesystems)
{
my $message = << "EOF";
An error occurred while restoring from tape.
As there were no filesystems listed for backup in /etc/flexbackup.conf
the correct dump file on the tape could not be located.
EOF
NotifyAdmin("Tape restore failed", $message);
die "Tape restore failed: no filesystems listed for backup"
. " in $cfg::filesystems.\n";
}
my $tapefile = &FindTapeFile($filesystem);
++$tapefile; # Skip the index file
&ProbeTape($cfg::device);
&RewindTape($cfg::device);
&FSFTape($cfg::device, $tapefile);
my $tape_blocksize = &DetermineBlocksize($cfg::device);
&RewindTape($cfg::device);
&FSFTape($cfg::device, $tapefile);
&CreateFileList($tempfile);
&ExtractFiles($filesystem, $tempfile, $tape_blocksize);
###########################################################################
sub FindTapeFile ($)
{
# Need to locate which file on the tape contains the dump of the
# root filesystem. Assume it is a one tape archive for the moment.
my $filesystem = shift;
foreach (@cfg::filesystems)
{
if (m:\W*$filesystem\W*:)
{
my @fs = split(/\s+/, $_);
for (my $i = 0; $i < @fs; $i++)
{
return $i if ($fs[$i] eq "$filesystem")
}
}
my $message = << "EOF";
An error occurred while restoring from tape.
The $filesystem filesystem is not listed on the first tape.
EOF
NotifyAdmin("Tape restore failed", $message);
die "Tape restore failed: $filesystem filesystem is not listed"
. " on the first tape.\n";
}
}
sub ProbeTape ($)
{
my $device = shift;
system("/bin/mt -f $device status > /dev/null 2>&1");
if ($CHILD_ERROR)
{
my $message = << "EOF";
An error occurred while restoring from tape.
No tape loaded at $device.
EOF
NotifyAdmin("Tape restore failed", $message);
die "Tape restore failed: no tape loaded at $device.\n";
}
}
sub RewindTape ($)
{
my $device = shift;
system("/bin/mt -f $device rewind > /dev/null 2>&1");
if ($CHILD_ERROR)
{
my $message = << "EOF";
An error occurred while restoring from tape.
Could not rewind tape at $device.
EOF
NotifyAdmin("Tape restore failed", $message);
die "Tape restore failed: could not rewind tape at $device.\n";
}
}
sub FSFTape ($$)
{
my $device = shift;
my $files = shift;
system("/bin/mt -f $device fsf $files > /dev/null 2>&1");
if ($CHILD_ERROR)
{
my $message = << "EOF";
An error occurred while restoring from tape.
Could not position tape at file $files at $device.
EOF
NotifyAdmin("Tape restore failed", $message);
die "Tape restore failed: could not position tape at $device.\n";
}
}
sub DetermineBlocksize($)
{
my $device = shift;
use File::Temp 'tempdir';
use File::stat;
my $dir = File::Temp::tempdir( CLEANUP => 1 );
my $file = "$dir/xx";
system("dd", "if=$device", "bs=1M", "count=1", "of=$file");
my $st = stat($file) or die "No $file: $!";
return (($st->size)/1024);
}
sub DetermineBackupType
{
my $device = shift;
my $magic = `/usr/bin/file -sz $device 2>/dev/null`;
return "tar" if ($magic =~ /tar archive/);
return "dump" if ($magic =~ /new-fs dump file/);
return undef;
}
sub CreateFileList ($)
{
my $file = shift;
unless (open(FILE, "> $file"))
{
my $error = $!;
my $message = << "EOF";
An error occurred while restoring from tape.
Could not open temporary file $file for writing: $!.
EOF
NotifyAdmin("Tape restore failed", $message);
die "Tape restore failed: Could not open temporary file"
. " $file for writing: $error\n";
}
foreach (@restore)
{
print FILE "$_\n";
}
close FILE;
}
sub ExtractFiles ($$$)
{
my $filesystem = shift;
my $filelist = shift;
my $blocksize = shift;
unless (chdir $filesystem)
{
my $error = $!;
my $message = << "EOF";
An error occurred while restoring from tape.
Could not change directories to $filesystem: $!.
EOF
NotifyAdmin("Tape restore failed", $message);
die "Tape restore failed: could not change directories"
. " to $filesystem. $error\n";
}
$ENV{'PATH'} = "/bin:/usr/bin:/sbin";
system(
"/usr/bin/flexbackup",
"-extract",
"-d", "blksize=$blocksize",
"-flist",
$filelist
);
if ($CHILD_ERROR)
{
my $message = << "EOF";
An error occurred while restoring from tape.
Flexbackup returned with an error. For more details concerning this
error see:
/var/log/messages
/flexbackup.extract.log
EOF
NotifyAdmin("Tape restore failed", $message);
die "Tape restore failed: flexbackup error.\n";
}
unlink $filelist;
my $message = << "EOF";
Restoring from tape was successful.
For more details concerning this successful restore see:
/var/log/messages
/flexbackup.extract.log
EOF
NotifyAdmin("Tape restore succeeded", $message);
}
sub NotifyAdmin ($$)
{
my $subject = shift;
my $message = shift;
open(DATEMAIL, "|-")
or exec qw(/var/qmail/bin/datemail -t);
print DATEMAIL << "EOF";
To: admin
Subject: $subject
$message
EOF
close DATEMAIL;
}

View File

View File

View File

View File

@@ -0,0 +1,15 @@
{
# ----------------------------------------------------------------------
# Parameters for 'afio' only
# True to show block numbers}
$afio_echo_block = 'false';
{
# Files less than this size (kilobytes) won't be compressed}
$afio_compress_threshold = '3';
{
# Maximum amount of memory (megabytes) to use for temporary storage of
# compression results. If a compressed file is bigger than this, compression
# will have to run twice on the file (see manpage).}
$afio_compress_cache_size = '2';

View File

@@ -0,0 +1,13 @@
{
# Block size (k) to use (default for most things is 10)
# mt_var_blksize says to use "variable" block size for the tape device
# (mt setblk 0)
# If false, will use the $blksize parameter above. All non-mt commands
# will still use $blksize regardless of this value.
my $blksize = $flexbackup{Blocksize} || '32';
$OUT = '$blksize = "' . $blksize . '";';
$OUT .= "\n";
my $mt_blksize = $flexbackup{TapeBlocksize} || '0';
$OUT .= '$mt_blksize = "' . $mt_blksize . '";';
}

View File

@@ -0,0 +1,5 @@
{# Buffering}
$buffer = '{ $flexbackup{BufferProg} || 'buffer' }'; {# name of buffer program to help streaming}
$buffer_megs = '{ $flexbackup{BufferMegs} || '20' }'; {# buffer memory size (in megabytes)}
$pad_blocks = 'true'; {# true to pad blocks to blocksize}

View File

@@ -0,0 +1,4 @@
{# Compression}
$compress = 'gzip'; {# one of false/gzip/bzip2/compress/hardware}
$compr_level = '4'; {# compression level (1-9) (for gzip/bzip2/zip)}

View File

@@ -0,0 +1,6 @@
{# ----------------------------------------------------------------------
# Parameters for 'cpio' only
# Format of cpio archive}
$cpio_format = 'newc';

View File

@@ -0,0 +1,11 @@
{# Device to backup to - non-rewinding version please!
#
# Examples:
# Linux SCSI: /dev/nst0 Linux IDE: /dev/nht0
# Linux ftape: /dev/nqft0 FreeBSD SCSI: /dev/nrsa0
#
# If a directory, archive to files in that directory rather than a device
#
my $device = $backup{'Device'} || '/dev/nst0';
$OUT .= "\$device = '$device';";
}

View File

@@ -0,0 +1,11 @@
{# ----------------------------------------------------------------------
# Parameters for 'dump' only
# Estimated tape size (in kilobytes). This number doesn't really do much
# but help 'dump' get size estimates if set to zero uses 'dump -a'}
$dump_length = '0';
{
# True to use /etc/dumpdates (could mess things up if you dump subdirectories
# of mount points). False to use flexbackup's timestamps.}
$dump_use_dumpdates = 'false';

View File

@@ -0,0 +1,6 @@
# Set this to "true" to make erase operations just rewind - not really
# call "mt erase". For some tape drives, erase takes hours rather
# than seconds.
$erase_rewind_only = '{
$flexbackup{erase_rewind_only} || 'false'
}';

View File

@@ -0,0 +1,4 @@
{# If true (default), level zero "set" assumes you want to erase and use
# a new tape. If false, level zero "set" appends like all other backups}
$erase_tape_set_level_zero = 'true';

View File

@@ -0,0 +1,8 @@
{# Exclude files that match these *regular expressions* (not shell wildcards)
# from the backups (no affect on 'dump' archives). You can list more than one,
# just keep incrementing the index in the brackets for each. Also, strip off
# leading directories (the filesystem specs above or the "-fs" flag).
# Comment these out to exclude nothing.}
$exclude_expr[0] = 'news/articles';
$exclude_expr[1] = '.*~$'; {#'# single quote so emacs font-lock is happy}
$exclude_expr[2] = './aquota.*';

View File

@@ -0,0 +1,9 @@
{# Other global flags}
$remoteshell = 'ssh'; {# command for remote shell (rsh/ssh/ssh2)}
$remoteuser = ''; {# secondary user name for remote shells (not set) }
$label = 'true'; {# store identifying label in archive }
$verbose = 'false'; {# echo each file? (for afio/tar/cpio/zip)}
$sparse = 'true'; {# handle sparse files (for afio/tar/cpio)}
$indexes = 'true'; {# false to turn off all table-of-contents support}
$atime_preserve = 'true'; {# preserve access time (if possible) during backup }
$staticfiles = 'false'; {# Use non-dated filename if backing up to file }

View File

@@ -0,0 +1,16 @@
{# ----------------------------------------------------------------------
# Log/stamp files, path for temporary files
}
$staticlogs = "false"; {# use dated log files}
$logdir = "/var/log/flexbackup"; {# directory for log files}
$stampdir = "/var/state/flexbackup"; {# directory for backup timestamps}
$index = "$stampdir/index"; {# DB filename for tape indexes}
$comp_log = "gzip"; {# compress log? false/gzip/bzip2/compress}
$prefix = ""; {# log files will start with this prefix}
$sprefix = ""; {# stamp files will start with this prefix}
$tmpdir = "/tmp"; {# used for temporary refdate files, etc}
{
# Why do I suggest /var/state/flexbackup for the stamp/indexes?
# See the FHS, http://www.pathname.com/fhs/2.0/fhs-5.11.html
# BSD users probably want /var/db/flexbackup
}

View File

@@ -0,0 +1,5 @@
{
$OUT =<<'HERE';
$mt{'tell'} = 'status';
HERE
}

View File

@@ -0,0 +1,4 @@
{# File extensions that should not be compressed (seperate with spaces)
# For afio and zip only (since they do each file individually)}
$nocompress_types = 'mp3 Z z gz gif zip lha jpeg jpg taz tgz deb rpm bz2';

View File

@@ -0,0 +1,9 @@
{# ----------------------------------------------------------------------
# Parameters for 'tar' only
# True to show record numbers}
$tar_echo_record_num = 'false';
{
# True to preserve file access times}
$tar_atime_preserve = 'true';

View File

@@ -0,0 +1,4 @@
{# Span across filesytems? ("dump" will ignore this option)
# Set to "false" (don't) , "local" (all but nfs), or "all" (everything)}
$traverse_fs = 'false';

View File

@@ -0,0 +1,4 @@
{# ----------------------------------------------------------------------
# Parameters for 'zip' only
}

View File

@@ -0,0 +1,31 @@
{
# List the filesystems you wish to dump when 'all' is given
# Just a simple space-separated list
# Remote filesystems should denoted as 'host:dir'
#
# Example:
# $filesystems[0] = '/ /usr /home machine1:/usr machine2:/home';
#
# If you want an 'all' level 0 backup to span multiple tapes, add more lines
# You will be prompted for tape change in between.
#
my @filesys = ();
my $outstring;
open(FSTAB, "</etc/fstab") or die "Can't open fstab file";
while (<FSTAB>)
{
/\S+\s+(\S+)\s+(\S+)\s+(\S+)/ &&
($2 eq "ext2" or $2 eq "ext3" or $2 eq "ext4" or $2 eq "xfs") &&
$3 !~ /(?:noauto|loop)/ &&
$1 !~ /^\/var\/spool\/squid/ &&
$1 !~ /^\/boot$/ &&
push @filesys, $1;
}
close FSTAB;
$outstring = "\$set{'full'} = '";
$outstring .= join(' ', @filesys);
$outstring .= "';";
$outstring;
}

View File

@@ -0,0 +1,10 @@
{
my @prunelist = split(',', $flexbackup{Prune} || '');
return "" unless (scalar @prunelist);
$OUT = '$prune';
$OUT .= "{'/'} = '";
$OUT .= join(' ', @prunelist);
$OUT .= "';";
}

View File

@@ -0,0 +1,4 @@
$type = '{# Archive type? afio, dump, tar, cpio, or zip
my $type = $flexbackup{Type} || 'tar';
$OUT = "$type";
}';