http://www.perlmonks.org?node_id=956669


in reply to Firebird databases backup script

Don't shell out to cd, use chdir

single quotes do not interpolate, so print 'cd $fbbin' prints literally cd $fbbin not cd /opt/firebird/bin

This is where you syntax error was, you were missing a closing single quote

Don't do localtime date math yourself, use strftime

use POSIX(); print POSIX::strftime('%Y-%m-%d-%H-%M-%S', localtime);

Don't shell out to ls, use glob function, so  my @files = glob "*.$type";

Thats it :)

Replies are listed 'Best First'.
Re^2: Firebird databases backup script
by Mery84 (Novice) on Feb 28, 2012 at 15:21 UTC
    Thanks for your help. One issue fixed. Now I have problem to succesfully execute the most important backup command. Second foreach loop have system command (below pasted latest, fixed a bit version):
    foreach (@files) { chdir($fbbin); print "Tworze kopie bazy $_ \n"; system('./gbak -user sysdba -password masterkey -BACKUP_DATABA +SE localhost:$bazy$_ $kopie$_.gbk') or print "Blad archiwizowania baz +y $_ \n"; print "Gotowa kopia bazy $_ \n"; }
    I`ve try it in many ways in single quotes `` or '' also in "" always command output is the same:
    gbak: ERROR:requires both input and output filenames gbak:Exiting before completion due to errors sh: 2: /mnt/storage/testy/simplemarketing.gdb: not found sh: 3: .gbk: not found Gotowa kopia bazy simplemarketing.gdb
    It looks like the ./gbak command from Firebird binaries don`t reads the variables correctly. By hand this command looks:
    ./gbak -user sysdba -password masterkey -BACKUP_DATABASE localhost:/op +t/databases/demo.gdb /mnt/storage/testy/demo.gdb.gbk
    and works without problems. In my script: /opt/dabasaes/ comes from $bazy demo.gdb - database filename should be inserted by $_ from table @files destination dir /mnt/storage/testy/ should be inserted by $localdir and extended by .gbk file extension. But from perl script this command don`t work....

      Single quotes do not interpolate, but double quotes do, so use "" (this part explained in basic syntax section of perlintro )

      Its time like these I yearn for a perlquote :)