Re: [BackupPC-users] host config file command line editor ?

2009-01-08 Thread Chris Robertson
Alex wrote:
 Hi there, 
 i'm not aware using Perl scripting, but ok with bash / php.
 Then, i'd like to know if there's a way to set values for per pc config file 
 using command line tool ?

 By exemple, like to change only FullKeepCnt value, but, has it is by default 
 written that way :
 $Conf#123;FullKeepCnt#125; = #91;
 nbsp; '400'
 #93;;
   

That's HTML for...

$Conf{FullKeepCnt} = [
 '400'
];

It should not be HTML encoded on disk.

$Conf is a hash.  The hash entry FullKeepCnt is a list (I think) with, 
in this case, one value: 400.

 It's a bit hard for me to parse this file and write back a new value.

PHP has the htmlspecialchars_decode 
(http://us.php.net/manual/en/function.htmlspecialchars-decode.php), 
which will take the nasty looking string you started with, and transform 
it to the proper on-disk setup, which should also be easier to 
manipulate (I think PHP might even properly utilize Perl hashes).

  

 Didn't find any way of doing this on the wiki. I'd like to be able to do that 
 kind of thing without de cgi web interface, in order for me to be able to 
 change values through scripts.

 Thank you in advance for any advices :)

Chris

--
Check out the new SourceForge.net Marketplace.
It is the best place to buy or sell services for
just about anything Open Source.
http://p.sf.net/sfu/Xq1LFB
___
BackupPC-users mailing list
BackupPC-users@lists.sourceforge.net
List:https://lists.sourceforge.net/lists/listinfo/backuppc-users
Wiki:http://backuppc.wiki.sourceforge.net
Project: http://backuppc.sourceforge.net/


Re: [BackupPC-users] host config file command line editor ?

2009-01-08 Thread Holger Parplies
Hi,

Alex wrote on 2009-01-08 10:41:35 -0500 [[BackupPC-users]  host config file 
command line editor ?]:
 i'm not aware using Perl scripting, but ok with bash / php.

learn Perl, it's much more fun :-).

 Then, i'd like to know if there's a way to set values for per pc config
 file using command line tool ?

'vi host.pl' ?

 By exemple, like to change only FullKeepCnt value, but, has it is by default
 written that way :
 $Conf#123;FullKeepCnt#125; = #91;
 nbsp; '400'
 #93;;
 
 It's a bit hard for me to parse this file and write back a new value. 

I can see why that would be ...

 [...] I'd like to be able to do that kind of thing without de cgi web
 interface, in order for me to be able to change values through scripts.

Well, I don't know of any existing tool. It much depends on what you want to
do and be able to do.

- Can you guarantee that the host.pl files will never be modified through
  the web interface?
- Do you want to keep comments etc. in the host.pl files or just the settings?
- How do you suggest setting anything more complex than a simple string value
  (arrays, hashes, hashes of arrays)?
- BackupPC may accept different types of values for one parameter.
  BackupFilesExclude, for example, can be a string, an array of strings, or a
  hash of arrays of strings. Do you want to handle all cases correctly?

Depending on your answers, you could re-format your host.pl files to put each
assignment on one line (with some tending to get rather long) and then use
'sed' to modify them, do some perl -e 'use Data::Dumper; ...'-magic (I
started a small script but dropped it when the array question came up) ... you
could probably even use BackupPC::CGI::EditConfig, though I doubt emulating a
CGI POST request and supplying all the values is what you really had in mind.

Actually, I just added another few lines to the script for handling the first
hash/array cases that spring to mind, as well as removing values. It's not
extensively tested, but since I quick-hack(tm)ed it, I might as well include
it, just in case it fits anyone's needs. I'm not going to use it myself, as
I'd like to preserve comments in my config files.

Questions as to how to use it will be answered if posted to the mailing list
directly ;-). For the beginning, try

BackupPC_editconf.pl -f /etc/backuppc/testhost.pl FullKeepCnt=399 
'BackupFilesExclude{/}[0]=/sys'

Attachments can apparently not be accessed via Backup Central, which doesn't
really bother me. See the real mailing list archive instead:

http://sourceforge.net/mailarchive/forum.php?thread_name=1231429295.m2f.295958%40www.backupcentral.comforum_name=backuppc-users

Regards,
Holger
#!/usr/bin/perl -w
#
# Author: Holger Parplies, 09.01.09, GPL, uncommented, -*-quick-hack-*-

use strict;
use Data::Dumper;
use Getopt::Std;

$Data::Dumper::Terse = 1;

my %opts = (
	f = undef,		# file name of config file to manipulate
   );

if (not getopts ('f:', \%opts) or @ARGV == 0 or not defined $opts {f}) {
  die Usage: $0 -f host.pl VAR=VALUE ...\n;
}

our %Conf = ();
do $opts {f}
  or die Can't do $opts{f}: $!\n;

foreach (@ARGV) {
  my ($var, $val) = m/^\s*(.*?)\s*(?:=\s*(.*?)\s*)?$/;
  my $confvar;
  if ($var =~ /^(.*)\{(.*)\}\[(.*)\]$/) {
defined $val ? $Conf {$1} {$2} [$3] = $val
		 : splice @{$Conf {$1} {$2}}, $3, 1;
  } elsif ($var =~ /^(.*)\[(.*)\]$/) {
defined $val ? $Conf {$1} [$2] = $val : splice @{$Conf {$1}}, $2, 1;
  } elsif ($var =~ /^(.*)\{(.*)\}$/) {
defined $val ? $Conf {$1} {$2} = $val : delete $Conf {$1} {$2};
  } else {
defined $val ? $Conf {$var} = $val : delete $Conf {$var};
  }
}

open CONF, $opts{f}.new
  or die Can't create new configuration file $opts{f}.new: $!\n;
foreach (sort keys %Conf) {
  my $val = Data::Dumper::Dumper ($Conf {$_});
  chomp ($val);
  print CONF \$Conf {$_} = $val;\n;
}
close CONF;

rename $opts {f}, $opts{f}.old;
rename $opts{f}.new, $opts {f};

--
Check out the new SourceForge.net Marketplace.
It is the best place to buy or sell services for
just about anything Open Source.
http://p.sf.net/sfu/Xq1LFB___
BackupPC-users mailing list
BackupPC-users@lists.sourceforge.net
List:https://lists.sourceforge.net/lists/listinfo/backuppc-users
Wiki:http://backuppc.wiki.sourceforge.net
Project: http://backuppc.sourceforge.net/


Re: [BackupPC-users] host config file command line editor ?

2009-01-08 Thread Jeffrey J. Kosowsky
Alex wrote at about 10:41:35 -0500 on Thursday, January 8, 2009:
  
  Hi there, 
  i'm not aware using Perl scripting, but ok with bash / php.
  Then, i'd like to know if there's a way to set values for per pc config file 
  using command line tool ?
  
I'm having a little trouble understanding your English (not ur fault)
but it seems like you are looking to use bash or php to do per-host
configuration.

Since the config files (and BackupPC itself) are written in Perl, it
would seem that Perl is the natural language to use.
If you only want to set variables on a per-machine basis, you just
need to copy/paste/edit the existing config file for each machine --
you don't really need to know any Perl except the most basic of
variable and array assignment syntax.

If you want to 'hack' the config script to run some actual perl code
(and not just assign static variables) then you may need to know a
little Perl code and I have posted last month some tricks you can use.

  By exemple, like to change only FullKeepCnt value, but, has it is by default 
  written that way :
  $Conf#123;FullKeepCnt#125; = #91;
  nbsp; '400'
  #93;;
  
  It's a bit hard for me to parse this file and write back a new value. 
  
  Didn't find any way of doing this on the wiki. I'd like to be able to do 
  that kind of thing without de cgi web interface, in order for me to be able 
  to change values through scripts.
  
  Thank you in advance for any advices :)
  
  +--
  |This was sent by alexan...@inforeseau.com via Backup Central.
  |Forward SPAM to ab...@backupcentral.com.
  +--
  
  
  
  --
  Check out the new SourceForge.net Marketplace.
  It is the best place to buy or sell services for
  just about anything Open Source.
  http://p.sf.net/sfu/Xq1LFB
  ___
  BackupPC-users mailing list
  BackupPC-users@lists.sourceforge.net
  List:https://lists.sourceforge.net/lists/listinfo/backuppc-users
  Wiki:http://backuppc.wiki.sourceforge.net
  Project: http://backuppc.sourceforge.net/
  

--
Check out the new SourceForge.net Marketplace.
It is the best place to buy or sell services for
just about anything Open Source.
http://p.sf.net/sfu/Xq1LFB
___
BackupPC-users mailing list
BackupPC-users@lists.sourceforge.net
List:https://lists.sourceforge.net/lists/listinfo/backuppc-users
Wiki:http://backuppc.wiki.sourceforge.net
Project: http://backuppc.sourceforge.net/