I have some perl code which I may offer a little here. This is for 1.32
bacula so some of the restore fudges may now be addressed in the newer
version., i.e storage=<device> probably now works.

We do what you ask for laptop users who come into the office
occationally. I have a script which pings them and if it detects them
and they haven't backed up for 'n' days it emails them to do a backup
via the web interface. I can't give the complete code as it is too
specific for our site, and I don't have permission to distribute it. But
these 2 routines are the interface to bacula console. If perl is no use
to you then, bin this. However, using shell will be more difficult IMHO.

****************************************

use IPC::Open2;
use IO::Handle;

my @jobs = console_cmd( ".jobs" );
<snip>

#
========================================================================
=====

sub extract_all {
    # This is todo with the way we handle the state of where we are in
the web dialog.
    # So ignore for this example.
    my $active = shift;
    return unless $active;

    my $files = restore_cmd( 1 );

    print h3( "Extracting $files file(s) now started. You may continue
to do other things." ),
          p( "You will receive an email from Bacula when complete." );
}

#
========================================================================
=====

sub extract {
    my $active = shift;
    return unless $active;

    # get file list from web page.
    my @files = param('files');

    my $filename = $USERDIR . RESTORELIST;

    open my $restore, ">$filename" or die "Can't open restore list file
'$filename' for writing: $!";
    print $restore join( "\n", @files ), "\n";
    close $restore;

    my $files = restore_cmd( 0, $filename );
    print h3( "Extracting $files file(s) now started. You may continue
to do other things." ),
          p( "You will receive an email from Bacula when complete." );
}

#
========================================================================
=====

sub console_cmd {
    my $cmd = shift;

    my( $reader, $writer ) = ( IO::Handle->new, IO::Handle->new );
    my @output;
    eval {
        open2( $reader, $writer, BCONSOLE );
        print $writer "$cmd\n.quit\n";
        @output = <$reader>;
    };
    if( $@ ) {
        die "Can't run console: [EMAIL PROTECTED]";
    }
    close $reader;
    close $writer;
    splice @output, 0, 3;
    pop @output;
    chomp @output;
    return @output;
}

#
========================================================================
=====
# Define $full if you want to force a full backup, otherwise provide a
list
# of files to restore in a file and pass the filename as $filename.

sub restore_cmd {
    my( $full, $filename ) = @_;

    # storage parameter doesn't work at the moment.
    my $command = "restore client=$USER-fd storage=$USER-st ";
    if( $full ) {
        $command .= "select";
    }
    else {
        $command .= "file=<$filename";
    }

    my( $reader, $writer ) = ( IO::Handle->new, IO::Handle->new );
    $reader->autoflush( 1 );
    $writer->autoflush( 1 );
    my $files;
    eval {
        open2( $reader, $writer, BCONSOLE );
        $writer->print( "$command\n" );
        my( $output, $storage );
        do {
            1 while $output = $reader->getline() and $output !~ /^The
defined (\w+) resources are/;
            if( $1 eq "FileSet" ) {
                my $fileset;
                # The select line is not terminated so need to pre-read
the first few chars.
                while( $reader->read( $output, 3 ) and $output ne "Sel"
) {
                    $output = $reader->getline();
                    $output =~ /(\d+):\s+\d+\s+$USER-fs/;
                    $fileset = $1;
                }
                # Select the latest one.
                $writer->print( "$fileset\n" );
            }
            elsif( $1 eq "Storage" ) {
                1 while $output = $reader->getline() and $output !~
/(\d+):\s+$USER-st/;
                $storage = $1;
            }
            else {
                die( "Something else we need to specify" );
            }
        } until( $storage );
        # This overcomes the storage problem.
        $writer->print( "$storage\n" );
        # This selects all files.
        $writer->print( "done\n" ) if $full;
        1 while $output = $reader->getline() and $output !~ /(\d+)
files? selected to restore/;
        $files = $1;
        # Agree to anything, just restore my bl**dy files.
        $writer->print( "yes\n.quit\n" );
        # flush the reader;
        $reader->flush();
    };
    if( $@ ) {
        die "Can't run console: [EMAIL PROTECTED]";
    }
    $reader->close();
    $writer->close();
    return $files;
}


-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Rick
Meyer
Sent: 12 April 2005 14:44
To: 'Richard Caley'; 'Emery Guevremont'
Cc: bacula-users@lists.sourceforge.net
Subject: RE: [Bacula-users] Initiating a backup from a windows client

I say your shell stuff is worth working on.

I would like to be able to initiate this from a webpage on the Linux
server
from a Windows client.

I would also like to be able to browse backed-up files from a webpage on
the
Linux host (files are stored on disk - ie not tape) then select a job to
restore back to the windows client.

So if this is worth something to other out there I'll do the webpage
interface, if someone can figure out how to execute the proper console
@commands to restore the files to the windows client, or perhaps there
is
another way.  

Rick Meyer

> -----Original Message-----
> From: [EMAIL PROTECTED] [mailto:bacula-users-
> [EMAIL PROTECTED] On Behalf Of Richard Caley
> Sent: Tuesday, April 12, 2005 8:58 AM
> To: Emery Guevremont
> Cc: bacula-users@lists.sourceforge.net
> Subject: Re: [Bacula-users] Initiating a backup from a windows client
> 
> Here is the script I use to kick of backups of not-always-there
> machines. It's a little hacky, but does the job for me.
> 
> Some assumptions:
> 
>      The client foo is the bacula file demon foo-fd
> 
>      You want to run Differential backups of foo every day it is
>      actually available to be backed up.
> 
>      You have a job which is sheduled never to run automatically which
>      when run by this script will do today's backup. For stupid shell
>      reasons it is important that the job name not contain spaces. In
>      the example below, FooJob.
> 
>      The bacula console config on host bachost is
> 
>        /usr/local/etc/bacula-bachost.conf
> 
> I have been thinking of extending this to be able to run a full backup
> every month or similar, if anyone actually thinks this is interesting
> enough to be worth working on I'll give it a go.
> 
> 
> I run this every hour from root's crontab on the bacula director's
> machine as follows.
> 
>       bacula_backup_if_ready bachost foo-fd 1 FooJob
> 
> Meaning `talk to the bacula console on bachost and if foo has not been
> backed up for at least 1 day, and it is up and available, back it up
> by running FooJob.
> 
> I have only run this on FreeBSD, so there could be minor issues with
> where things are related on other systems.
> 
> --- 8< --- 8< --- CUT HERE for bacula_backup_if_ready --- 8< --- 8<
---
> #!/bin/sh
> 
> if [ $# -lt 3 ]
>       then
>       echo "Use: $0 HOST CLIENT DAYS" JOB1 JOB2...
>       exit 1
> fi
> 
> # set -x
> 
> host=${1-`hostname`}
> 
> host=`expr "$host" : '^\([^.]*\).*'`
> 
> exec > /var/log/bacula_oportunistic-$host 2>&1
> 
> conf=/usr/local/etc/bacula-$host.conf
> 
> client="$2"
> days="$3"
> 
> shift 3
> 
> client_host=`expr "$client" : '\(.*\)-fd'`
> 
> # Shell function which runs a command via the
> # bacula console.
> 
> bacula_command()
> {
> t="$1"
> c="$2"
> 
> shift 2
> 
> { echo "$c"; for a in "$@" ; do echo "$a"; done; } |
> /usr/local/sbin/console -c "$conf"&
> 
> bacula_pid=$!
> 
> (sleep $t; kill $bacula_pid 2>/dev/null >&2)&
> 
> wait $bacula_pid
> }
> 
> # Check timestamp to see if we are due a backup.
> 
> [ -d /var/bacula_timestamps ] || mkdir /var/bacula_timestamps
> 
> timestamp=`find /var/bacula_timestamps -name $client -mtime -$days`
> 
> echo timestamp=$timestamp
> 
> if [ -z "$timestamp" ]
>       then
>       if /sbin/ping -c 1 $client_host && bacula_command 10 "status
> client=$client"
>               then
>               for job in "$@"
>                       do
>                       if bacula_command 10 "run \"$job\"" "mod" "1"
"4"
"yes"
>                               then
>                               echo -n > /var/bacula_timestamps/$client
>                       fi
>               done
>       fi
> fi
> 
> 
> --- 8< --- 8< --- bacula_backup_if_ready end --- 8< --- 8< ---
> 
> 
>       ^_^
>      (O O)
>      \_/@@\
>       \\~~/
>         ~~
>               - RJC
> 
> 
> -------------------------------------------------------
> SF email is sponsored by - The IT Product Guide
> Read honest & candid reviews on hundreds of IT Products from real
users.
> Discover which products truly live up to the hype. Start reading now.
> http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click
> _______________________________________________
> Bacula-users mailing list
> Bacula-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/bacula-users






-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users.
Discover which products truly live up to the hype. Start reading now.
http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click
_______________________________________________
Bacula-users mailing list
Bacula-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bacula-users



-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users.
Discover which products truly live up to the hype. Start reading now.
http://ads.osdn.com/?ad_ide95&alloc_id396&op=click
_______________________________________________
Bacula-users mailing list
Bacula-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bacula-users

Reply via email to