initial commit of file from CVS for e-smith-flexbackup on Wed 12 Jul 08:54:20 BST 2023
This commit is contained in:
@@ -0,0 +1 @@
|
||||
32
|
@@ -0,0 +1 @@
|
||||
20
|
@@ -0,0 +1 @@
|
||||
buffer
|
@@ -0,0 +1 @@
|
||||
0
|
@@ -0,0 +1 @@
|
||||
tar
|
@@ -0,0 +1 @@
|
||||
true
|
@@ -0,0 +1 @@
|
||||
backupservice
|
4
root/etc/e-smith/events/actions/tape-backup-flexbackup
Normal file
4
root/etc/e-smith/events/actions/tape-backup-flexbackup
Normal file
@@ -0,0 +1,4 @@
|
||||
#! /bin/sh
|
||||
|
||||
cd /
|
||||
exec /usr/bin/flexbackup -set all -noreten
|
327
root/etc/e-smith/events/actions/tape-restore-flexbackup
Normal file
327
root/etc/e-smith/events/actions/tape-restore-flexbackup
Normal 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;
|
||||
}
|
0
root/etc/e-smith/events/bootstrap-console-save/.gitignore
vendored
Normal file
0
root/etc/e-smith/events/bootstrap-console-save/.gitignore
vendored
Normal file
0
root/etc/e-smith/events/conf-backup/.gitignore
vendored
Normal file
0
root/etc/e-smith/events/conf-backup/.gitignore
vendored
Normal file
0
root/etc/e-smith/events/console-save/.gitignore
vendored
Normal file
0
root/etc/e-smith/events/console-save/.gitignore
vendored
Normal file
0
root/etc/e-smith/events/restore-tape/.gitignore
vendored
Normal file
0
root/etc/e-smith/events/restore-tape/.gitignore
vendored
Normal file
15
root/etc/e-smith/templates/etc/flexbackup.conf/10AfioParams
Normal file
15
root/etc/e-smith/templates/etc/flexbackup.conf/10AfioParams
Normal 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';
|
||||
|
13
root/etc/e-smith/templates/etc/flexbackup.conf/10Blocksize
Normal file
13
root/etc/e-smith/templates/etc/flexbackup.conf/10Blocksize
Normal 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 . '";';
|
||||
}
|
@@ -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}
|
||||
|
@@ -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)}
|
||||
|
@@ -0,0 +1,6 @@
|
||||
{# ----------------------------------------------------------------------
|
||||
# Parameters for 'cpio' only
|
||||
|
||||
# Format of cpio archive}
|
||||
$cpio_format = 'newc';
|
||||
|
11
root/etc/e-smith/templates/etc/flexbackup.conf/10Device
Normal file
11
root/etc/e-smith/templates/etc/flexbackup.conf/10Device
Normal 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';";
|
||||
}
|
11
root/etc/e-smith/templates/etc/flexbackup.conf/10DumpParams
Normal file
11
root/etc/e-smith/templates/etc/flexbackup.conf/10DumpParams
Normal 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';
|
||||
|
@@ -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'
|
||||
}';
|
@@ -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';
|
||||
|
@@ -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.*';
|
9
root/etc/e-smith/templates/etc/flexbackup.conf/10Globals
Normal file
9
root/etc/e-smith/templates/etc/flexbackup.conf/10Globals
Normal 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 }
|
16
root/etc/e-smith/templates/etc/flexbackup.conf/10Logging
Normal file
16
root/etc/e-smith/templates/etc/flexbackup.conf/10Logging
Normal 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
|
||||
}
|
5
root/etc/e-smith/templates/etc/flexbackup.conf/10MtTell
Normal file
5
root/etc/e-smith/templates/etc/flexbackup.conf/10MtTell
Normal file
@@ -0,0 +1,5 @@
|
||||
{
|
||||
$OUT =<<'HERE';
|
||||
$mt{'tell'} = 'status';
|
||||
HERE
|
||||
}
|
@@ -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';
|
||||
|
@@ -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';
|
||||
|
@@ -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';
|
||||
|
@@ -0,0 +1,4 @@
|
||||
{# ----------------------------------------------------------------------
|
||||
# Parameters for 'zip' only
|
||||
|
||||
}
|
31
root/etc/e-smith/templates/etc/flexbackup.conf/10filesystems
Normal file
31
root/etc/e-smith/templates/etc/flexbackup.conf/10filesystems
Normal 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;
|
||||
}
|
||||
|
10
root/etc/e-smith/templates/etc/flexbackup.conf/10prune_tree
Normal file
10
root/etc/e-smith/templates/etc/flexbackup.conf/10prune_tree
Normal file
@@ -0,0 +1,10 @@
|
||||
{
|
||||
my @prunelist = split(',', $flexbackup{Prune} || '');
|
||||
|
||||
return "" unless (scalar @prunelist);
|
||||
|
||||
$OUT = '$prune';
|
||||
$OUT .= "{'/'} = '";
|
||||
$OUT .= join(' ', @prunelist);
|
||||
$OUT .= "';";
|
||||
}
|
4
root/etc/e-smith/templates/etc/flexbackup.conf/10type
Normal file
4
root/etc/e-smith/templates/etc/flexbackup.conf/10type
Normal file
@@ -0,0 +1,4 @@
|
||||
$type = '{# Archive type? afio, dump, tar, cpio, or zip
|
||||
my $type = $flexbackup{Type} || 'tar';
|
||||
$OUT = "$type";
|
||||
}';
|
Reference in New Issue
Block a user