Help with perl mysql backup script

Hi, im trying to make a script that backups mysql databases but apparently I am having trouble with the variables, or simply something I am missing.

Would appreciate any help, here is the script

#!/usr/bin/perl -w
use strict;
require File::Spec;

#VARIABLES
my $databasename = 'test_db';             		 #project database name
my $scriptsdir = '/home/user/perl/';  	                 #script directory
my $project = 'kor';        			         # backup folder name, as created it on sftp server
my $backupdir = 'b0000000@hanjin.dreamhost.com:/test/';  #backup host directory


#date settings
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
my $ymd = sprintf("%04d-%02d-%02d-%02d-%02d-%02d",$year+1900,$mon,$mday,$hour,$min,$sec);
my $outdb = '$ymd-$databasename.tar.gz';


#BACKUPS MYSQL DB INFO
##Checks which action was called and mysql db backup in case its daily
my $action = $ARGV[0] ? $ARGV[0] : "";
if ($action eq "daily") {
system('mysqldump -u root $databasename | gzip > $scriptsdir$outdb');
system('scp $scriptsdir$outdb $backupdir$project/daily.0');
system('rm $scriptsdir$outdb');
}

Is it some module I am missing here? the message I get when I run this is :

sh: cannot create : Directory nonexistent

again, thx for any help

ps: this is part of a bigger script that rsync snapshots to the ftp, that is why I am using perl, the rest of the script is working just fine, only having trouble with this particular part

If you copied this over without changing anything, the first thing I notice is that you used single quotes, which won't interpolate any of the variables you're using.

1 Like

Thanks, that did fix the problem, but using double quotes on

my $backupdir = "b0000000@hanjin.dreamhost.com:/test/";  #backup host directory

it returns that @hanjin is interpolating,

Global symbol "@hanjin" requires explicit package name at ./production.pl line 11.

if I remove the double quotes it tells me

scp: /test/kor/daily.0: No such file or directory

any solution?

---------- Post updated at 09:23 AM ---------- Previous update was at 08:45 AM ----------

Update: i used

my $backupdir = "b0000000\@hanjin.dreamhost.com:/test/";  #backup host directory

with the backslash, but it still giving me the same

scp: /test/kor/daily.0: No such file or directory

Could you replace the system calls with a simple print , and check the output of that? Maybe a variable isn't set as expected.

its solved

Used

$conf{'backup_dest'} = 'b000000@hanjin.dreamhost.com:test/kor/';

and then just changed the variable on the script