in reply to Re^3: Firebird databases backup script
in thread Firebird databases backup script

Hello!

For now to cut out the first empty element from @files i`ve just used shift(@files);

No, it's not a good idea, better make sure the path is valid before adding it, or at least before calling gbak.

Using a file search and backup what it finds is also not a good idea for production code, maybe only as an learning exercise, for the reason you gave yourself, it may skip some databases without even noticing. Better to make a config with all databases to backup, check everything that you think (or even what you don't thing :) ) that it can go wrong and log the errors.

use strict; use warnings; my @files; my @ext = (qw{fb gdb ib fdb}); my $data = "/opt/databases/"; # notice the final / foreach my $ext (@ext) { my @load = glob "$data*.$ext"; push (@files, @load); } foreach my $db (@files) { if (-f $db) { print "Found database: $db \n"; } else { print "skiping '$db'...\n"; } } # Alternatively: foreach my $ext (@ext) { my @load = glob "$data*.$ext"; foreach my $file (@load) { if (-f $file) { push (@files, $file); } else { print "Something is wrong, with '$file'!\n"; } } } foreach my $db (@files) { print "Found database: $db \n"; }

Here is a piece from my backup script based on "IPC::Run3 - run a subprocess with input/ouput redirection", learned from Re^3: Using SYSTEM2 on Windows, thanks to ikegami :)

use strict; use warnings; use IPC::Run3 qw( run3 ); my $FBUSER = 'SYSDBA'; my $FBPASS = 'masterkey'; # this is secret ;) my $gbak = 'gbak'; my $host = 'localhost'; my $db = '/opt/databases/test.fdb'; my $bk = '/opt/databases/backup/test.fbk'; # Backup the database on remote (or local) server my $cmd = qq{$gbak -backup -service "$host:service_mgr" "$db" "$bk" -u +ser "$FBUSER" -pass "$FBPASS"}; run3 $cmd, undef, \my @out, \my @err; print "STDOUT: $_" for @out; if (scalar @err > 0) { print "\n--- Errors ---------------------------------------------- +---\n"; print " $_" for @err; print "----------------------------------------------------------- +-\n\n"; } else { print " Backup completed successfully.\n"; }

Regards, Ştefan

Update: refactored code that was silently skipping elements from the list.