in reply to Firebird databases backup script

Hello,
@Anonymous Monk
As I mentioned earlier I`ve tried both way in '' and "" and both don`t work.

@sundialsvc4
Thank for your nice opinion :).

For now i`ve fixed script a bit and translated it from polish descriptions and var names to english for easier reading for you :). Latest version of script:
#!/usr/bin/perl -w use strict; use warnings; #Variables my $fbbin = "/opt/firebird/bin/"; my $data = "/opt/databases/"; my $ext = "gdb"; #my $shared = "/opt/shared/"; my $tempdir = "/opt/backup/"; #my $destdir = "/home/mery/backup/complete/"; #my $usbdev = "/dev/sdc1/"; #my $localdir = "/mnt/storage/testy/"; #my $mailerr = "core-powiadomienia\@core.com.pl"; my $klient = "PanTester"; my $mailtopic = "Raport nocnej kopii zapasowej w firmie $klient"; use POSIX(); print POSIX::strftime('%Y-%m-%d-%H-%M-%S', localtime); #Create database filenames table @files my $type = $ext; my $dir = $data; $type = "*.$type"; print "looking for files with extension $type \n"; chdir ($dir); my @files = qx(ls $type 2>&1); foreach (@files) { print "Found database: $_\n"; } # This loop run external gbak backup command to create $_.gbk files as + output in $tempdir foreach (@files) { chdir ($fbbin); # print "Tworze kopie bazy $_ \n"; system("./gbak -user sysdba -password masterkey -BACKUP_DATABA +SE localhost\:$data$_ $tempdir`$_.gbk`") or die "Blad archiwizowania +bazy $_ \n"; # print "Gotowa kopia bazy $_ \n"; }
Output:
2012-02-28-22-23-33looking for files with extension *.gdb Found database: demo2.gdb Found database: demo.gdb Found database: SimpleMarketing2.gdb Found database: simplemarketing.gdb gbak: ERROR:requires both input and output filenames gbak:Exiting before completion due to errors sh: 1: demo2.gdb: not found sh: 2: .gbk: not found sh: 3: /opt/backup/: Permission denied gbak: ERROR:requires both input and output filenames gbak:Exiting before completion due to errors sh: 1: demo.gdb: not found sh: 2: .gbk: not found sh: 3: /opt/backup/: Permission denied gbak: ERROR:requires both input and output filenames gbak:Exiting before completion due to errors sh: 1: SimpleMarketing2.gdb: not found sh: 2: .gbk: not found sh: 3: /opt/backup/: Permission denied gbak: ERROR:requires both input and output filenames gbak:Exiting before completion due to errors sh: 1: simplemarketing.gdb: not found sh: 2: .gbk: not found sh: 3: /opt/backup/: Permission denied
/opt/backup is chmoded to 777 and owned by nobody.nogroup (it`s testing virtual machine so i`m not worried about security ;)) so i don`t understand why permission denied.

Replies are listed 'Best First'.
Re^2: Firebird databases backup script
by Anonymous Monk on Feb 28, 2012 at 23:04 UTC

    @Anonymous Monk As I mentioned earlier I`ve tried both way in '' and "" and both don`t work.

    But for different reasons. Using single quotes like that could never have worked, it would have never done what you are trying to do.

    Also, as system documents, using system or die is wrong, you need to use system(@args)==0 or die.

    or use autodie qw/ system /; and let autodie take care of the dying.

    This means the actual command you're trying to execute is wrong -- I see some backticks which looks like an error to me.

    What is the command you're trying to execute? What would it look like if you typed it in on the commandline, no variables, just the final text? Dumper it and see what you're trying to actually execute ( see

    Tutorials: Basic debugging checklist for Dumper)

    You might have better luck narrowing it down by giving system a list, as in

    use autodie qw/ system /; my @args = qw[ ./gbak -user sysdba -password masterkey -BACKUP_DATABAS +E ]; push @args, "localhost:$data$_" , "$tempdir$_.gbk"; use Data::Dumper; print "Trying to system(@args) ", Dumper(\@args ), "\n"; system @args;

    See systems for all the caveats, and use autodie, and when something doesn't work right, remember Basic debugging checklist

      Hello,
      By hand gbak command looks:
      ./gbak -user sysdba -password masterkey -BACKUP_DATABASE localhost:/opt/databases/demo.gdb /opt/backup/demo.gdb.gbk
      and works fine.
      Also in simple script:
      chdir ($fbbin); system("./gbak -user sysdba -password masterkey -BACKUP_DATABA +SE localhost:/opt/databases/demo.gdb /opt/databases/demo.gbk")==0 or +die "Failed to create backup file \n";

      I see where is the issue with loading details from variables to system command but i don`t have any idea how to fix it.
      See:
      foreach (@files) { chdir ($fbbin); print "./gbak -user sysdba -password masterkey -BACKUP_DATABAS +E localhost:$data$_ $tempdir$_.gbk \n";
      Gives me output:
      ./gbak -user sysdba -password masterkey -BACKUP_DATABASE localhost:/op +t/databases/simplemarketing.gdb /opt/backup/simplemarketing.gdb .gbk
      This output should be in one row not in three ;). It looks like enter pressed always after $_ variable loaded from @files table which contains databases filenames. Any ideas how to fix it?