BackupPC-users

Re: [BackupPC-users] Variable in Host Configuration File

2009-10-01 22:30:39
Subject: Re: [BackupPC-users] Variable in Host Configuration File
From: Holger Parplies <wbppc AT parplies DOT de>
To: Valarie Moore <jeixav AT gmail DOT com>
Date: Fri, 2 Oct 2009 04:26:45 +0200
Hi,

Valarie Moore wrote on 2009-10-01 16:11:16 +0000 [[BackupPC-users] Variable in 
Host Configuration File]:
> I have a host configuration file like this:
> 
> $Conf{ClientNameAlias} = 'localhost';
> $Conf{XferMethod} = 'rsync';
> $Conf{RsyncShareName} = '/home/jeixav';
> $Conf{RsyncClientCmd} = 'sudo -u jeixav $rsyncPath $argList+';
> $Conf{RsyncClientRestoreCmd} = 'sudo -u jeixav $rsyncPath $argList+';
> 
> I would like to specify the user account jeixav once as a variable, rather
> than having it "hardcoded" three times, but I'm don't know how to do this.
> Going through the BackupPC's config.pl file, it seems as though the variable
> called $user should help, [...]

no, it doesn't. Above $Conf {RsyncClientCmd}, the comment starting with "Full
command to run rsync on the client machine" does not list a variable $user.
For RsyncShareName, there is no substitution at all.

You don't tell us what the "name" of the host is (if the configuration file is
named "foo.pl", then your host name is "foo"). You are using ClientNameAlias
to override the host name for ... err ... the ping command (it is not used in
RsyncClient{,Restore}Cmd, so it has no other effect), so you've presumably
used something descriptive as host name. If your host is actually named
"jeixav", you can use $host in RsyncClientCmd and RsyncClientRestoreCmd (but
not RsyncShareName).

Depending on what you are exactly trying to achieve, there are several
further possibilities.

1. Avoid three occurrences of the same constant value for aesthetic reasons
   or ease of change

   Define a Perl variable in the config file and use it (you won't be able to
   use the web based config editor to make changes to the config file,
   though):

   my $user = 'jeixav';
   $Conf{RsyncShareName} = "/home/$user";
   $Conf{RsyncClientCmd} = "sudo -u $user \$rsyncPath \$argList";
   $Conf{RsyncClientRestoreCmd} = "sudo -u $user \$rsyncPath \$argList";

   Note the double quotes and the quotation of $-signs for the variables that
   are to be interpolated by BackupPC rather than Perl, though.

2. Reusability of the same config file for several users through hard links
   (/etc/backuppc/jeixav.pl, /etc/backuppc/user2.pl, /etc/backuppc/user3.pl
   etc. all point to the same file - this is assuming you are using the
   relevant user names as "host names" in BackupPC):

   Use Jeffrey's trick of looking for the host name in $_[1] inside the config
   file:

   $Conf{RsyncShareName} = "/home/$_[1]";
   $Conf{RsyncClientCmd} = "sudo -u $_[1] \$rsyncPath \$argList";
   $Conf{RsyncClientRestoreCmd} = "sudo -u $_[1] \$rsyncPath \$argList";

   The same notes apply as above.


Two unrelated remarks:

1. In any case, it should be "$argList", not "$argList+", as the value is not
   passed through a shell (see remark above $Conf{TarClientCmd} in config.pl
   for an explanation on shell quoting). The default value of RsyncClientCmd
   contains an 'ssh', so in that case $argList needs to be quoted. For 'sudo'
   it should not be (both will work as long as there is, in fact, nothing to
   quote, but you don't want it to break if you change the configuration at
   some point in the future).

2. For backups of localhost (and even more so if RsyncClientCmd does not even
   contain an 'ssh' or equivalent) you don't really need a PingCmd. Then
   again, you might want to keep it to simplify future changes. If you want to
   disable it, you can do so by setting

   $Conf{PingCmd} = '&{sub {0}}';

   I'm only mentioning this because *without* a PingCmd, ClientNameAlias
   doesn't do anything anymore, so you could probably drop it (though I'm not
   positive that BackupPC won't try to do a DNS lookup of the name, so you
   might need to keep it after all).

   But this is really more academic than in any way relevant. If in doubt,
   just leave PingCmd and ClientNameAlias as they are.

> I am using BackupPC as packaged with Debian 5.0.3 (lenny).

Which is 3.1.0, in case anyone was wondering.

Regards,
Holger

------------------------------------------------------------------------------
Come build with us! The BlackBerry&reg; Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay 
ahead of the curve. Join us from November 9&#45;12, 2009. Register now&#33;
http://p.sf.net/sfu/devconf
_______________________________________________
BackupPC-users mailing list
BackupPC-users AT lists.sourceforge DOT net
List:    https://lists.sourceforge.net/lists/listinfo/backuppc-users
Wiki:    http://backuppc.wiki.sourceforge.net
Project: http://backuppc.sourceforge.net/

<Prev in Thread] Current Thread [Next in Thread>