Help with perl mysql backup script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help with perl mysql backup script
# 1  
Old 08-11-2011
[SOLVED]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

Code:
#!/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 :

Code:
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

Last edited by Fireline; 08-11-2011 at 12:38 PM..
# 2  
Old 08-11-2011
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.
This User Gave Thanks to pludi For This Post:
# 3  
Old 08-11-2011
Quote:
Originally Posted by pludi
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.
Thanks, that did fix the problem, but using double quotes on

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


it returns that @hanjin is interpolating,
Code:
Global symbol "@hanjin" requires explicit package name at ./production.pl line 11.

if I remove the double quotes it tells me

Code:
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

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

with the backslash, but it still giving me the same

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


Last edited by Fireline; 08-11-2011 at 12:36 PM.. Reason: Solved
# 4  
Old 08-11-2011
Could you replace the system calls with a simple print, and check the output of that? Maybe a variable isn't set as expected.
# 5  
Old 08-11-2011
Quote:
Originally Posted by pludi
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

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

and then just changed the variable on the script

Last edited by Fireline; 08-11-2011 at 12:37 PM.. Reason: typo
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

I need perl script on cold backup in Oracle 10 g

Hi , I am new to Perl script.Can u please provide me perl scripts for the following: 1. Perl script on Cold backup in Oracle 10g 2.Perl script on Hot backup in Oracle 10g (0 Replies)
Discussion started by: Niharika Srivas
0 Replies

2. Web Development

Restore MySQL backup

Hello all! First posting here! So be patient with me. I made a clean install with MacOS 10.8 and need to restore my Databases from my external backup drive. Apparently it is not possible, to create the MySQL user and password as before, and simply drag the databases from... (12 Replies)
Discussion started by: marek
12 Replies

3. Shell Programming and Scripting

MySQL Restoration Backup Script

Hi there, Alright I have this line that I'm working with (bash programming): mysql -u username -pHASH ${args} < /home/site/backups/site.${args}.sql I get this error on that line: ./restore.sh: line 51: syntax error near unexpected token `newline' ./restore.sh: line 51: `mysql -u... (5 Replies)
Discussion started by: Pandoula
5 Replies

4. Shell Programming and Scripting

Script - Mysql backup and delete

Hello I have a production mysql server and archive server, unfortunitly its not possible to setup repliacation between the two, the reason is that the archive server is using some fancy storage engine which doesn't allow mysql replication. I'm trying to write a script using perl that does... (1 Reply)
Discussion started by: amlife
1 Replies

5. UNIX and Linux Applications

Online insert MySQL rows by perl-script

Hello, Met a problem when I tried to insert rows to MySQL database from an old book that fits my learning level (MySQL and Perl for the Web, by Paul DuBois, 2001). First, under mysql console I created a database: webdb and the table: todo. Then I draft the perl-cgi script to have online page.... (0 Replies)
Discussion started by: yifangt
0 Replies

6. Programming

Help with mySQL database by perl script

Hello; I was trying to set up a mysql database using following script, but never went through. The code seems fine without any syntax error as I tested it: perl -c Brapa0101-db.pl Brapa0101-db.pl syntax OKHowever, whenever I run it, an error message was tossed out: DBD::mysql::st execute... (7 Replies)
Discussion started by: yifangt
7 Replies

7. Shell Programming and Scripting

how to print out data from mysql table in perl script

I'm having trouble with this code. if i do .\read.pl -u user it prints out 2010-12-20 12:00:00 host1 <cmd>a 2010-12-20 12:00:01 host1 <cmd> <execute> 2010-12-20 12:00:02 host1 <cmd>b 2010-12-20 12:00:03 host1 <cmd>c however, if i enter .\read.pl -h host1 it should... (3 Replies)
Discussion started by: kpddong
3 Replies

8. Shell Programming and Scripting

perl script for generates a report for backup times

Hi all, we do have daily oracle database backups and i need to generate report of each database start point and end point we are using netapp snapshot(filer level) for backups. all backups logs will be come in one directory /u01/app/oracle/backup/hostname/log/* here... (7 Replies)
Discussion started by: prakashdba2010
7 Replies

9. Shell Programming and Scripting

Connecting MySql throug Perl Script ?

Dear Friends, I am tryin to connect to the myql through perl scrip. I have already installed mysql and DBI modules to my Perl. There versions are as follows, DBD-mysql MySQL driver for the Perl5 Database DBI Database independent interface for It gives... (4 Replies)
Discussion started by: maheshsri
4 Replies
Login or Register to Ask a Question