Home > Archive > PERL CGI Beginners > December 2005 > Backing Up Files to a Remote Server
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Backing Up Files to a Remote Server
|
|
| Adedayo Adeyeye 2005-12-14, 6:56 pm |
| Hello,
Please can someone please help me with a script that can basically do two
things:
1. check that a file was created today
2. backup that file to a remote server
This is to be done on a windows platform. I'll schedule this script to run
at the end of everyday.
Kind regards.
Adedayo Adeyeye
Netcom Africa Limited
Engineering
South Atlantic Petroleum Tower
7/F, 7 Adeola Odeku Street
Victoria Island, Lagos, Nigeria
a.adeyeye@netcomng.com
Tel:
234.1.461.1234
Skype: crownd
Fax:
234.1.461.1235
<http://www.netcomafrica.com/> http://www.netcomafrica.com
Mobile:
0802.501.3758
The information contained in this communication is confidential and may be
legally privileged. It is intended solely for the use of the individual or
entity to whom it is addressed and others authorized to receive it. If you
are not the intended recipient you are hereby notified that any disclosure,
copying, distribution or taking action in reliance of the contents of this
information is strictly prohibited and may be unlawful. Kindly destroy this
message and notify the sender by replying the email in such instances. We do
not accept responsibility for any changes made to this message after it was
originally sent and any views, opinions, conclusions or other information in
this message which do not relate to the business of this firm or are not
authorized by us. Netcom is not liable neither for the proper and complete
transmission of the information contained in this communication nor any
delay in its receipt.
| |
| Chris Devers 2005-12-14, 6:56 pm |
| On Wed, 14 Dec 2005, Adedayo Adeyeye wrote:
> Please can someone please help me with a script that can basically do two
> things:
>
> 1. check that a file was created today
> 2. backup that file to a remote server
>
> This is to be done on a windows platform. I'll schedule this script to run
> at the end of everyday.
Sounds like an interesting project.
How much have you budgeted to pay someone to do this for you?
If you want something for free, you're going to have show us the code
you have already tried. I didn't notice any in your email. Maybe I
wasn't looking hard enough.
Demonstrate that you're trying to solve this yourself, and we will be
happy answering any questions that come up as you're learning.
Starting points: <http://learn.perl.org/>, O'Reilly books, Google.com.
--
Chris Devers
| |
| Charles K. Clarkson 2005-12-14, 6:56 pm |
| Adedayo Adeyeye <mailto:a.adeyeye@netcomng.com> wrote:
: Thanks.
:
: To get the statistics of a file on my windows box, I ran the
: following script:
:
:
: open FILE1, "Perfect.xls" or die "Cannot open file: $!";
:
: my @stuff = stat "FILE1";
:
: print "@stuff";
:
: Unfortunately, I don't know why this never returned any values into
: my @stuff variable.
Because stat() works on filenames, not file handles.
my @stuff = stat 'Perfect.xls';
: Next I tried this:
:
: open FILE1, "Perfect.xls" or die "Cannot open file: $!";
:
: open FILE2, ">folder\Perfect.xls" or die "Cannot write to destination
: directory: $!";
In perl, directories are separated by "/" not "\". "\P" is an
escaped "P".
: system ("copy FILE1 FILE2");
:
: close FILE1;
: close FILE2;
use File::Copy 'copy';
copy( 'Perfect.xls', 'folder/Perfect.xls') or die "Copy failed: $!";
HTH,
Charles K. Clarkson
--
Mobile Homes Specialist
254 968-8328
| |
| Adedayo Adeyeye 2005-12-14, 6:56 pm |
| Thanks.
To get the statistics of a file on my windows box, I ran the following
script:
open FILE1, "Perfect.xls" or die "Cannot open file: $!";
my @stuff = stat "FILE1";
print "@stuff";
Unfortunately, I don't know why this never returned any values into my
@stuff variable. Next I tried this:
open FILE1, "Perfect.xls" or die "Cannot open file: $!";
open FILE2, ">folder\Perfect.xls" or die "Cannot write to destination
directory: $!";
system ("copy FILE1 FILE2");
close FILE1;
close FILE2;
I just kept getting the error : cannot find the file specified.
Kind regards
Adedayo Adeyeye
Netcom Africa Limited
Engineering
South Atlantic Petroleum Tower
7/F, 7 Adeola Odeku Street
Victoria Island, Lagos, Nigeria
a.adeyeye@netcomng.com
Tel:
234.1.461.1234
Skype: crownd
Fax:
234.1.461.1235
<http://www.netcomafrica.com/> http://www.netcomafrica.com
Mobile:
0802.501.3758
The information contained in this communication is confidential and may be
legally privileged. It is intended solely for the use of the individual or
entity to whom it is addressed and others authorized to receive it. If you
are not the intended recipient you are hereby notified that any disclosure,
copying, distribution or taking action in reliance of the contents of this
information is strictly prohibited and may be unlawful. Kindly destroy this
message and notify the sender by replying the email in such instances. We do
not accept responsibility for any changes made to this message after it was
originally sent and any views, opinions, conclusions or other information in
this message which do not relate to the business of this firm or are not
authorized by us. Netcom is not liable neither for the proper and complete
transmission of the information contained in this communication nor any
delay in its receipt.
| |
| Paul Lalli 2005-12-14, 6:56 pm |
| Charles K. Clarkson wrote:
> Adedayo Adeyeye <mailto:a.adeyeye@netcomng.com> wrote:
>
> : To get the statistics of a file on my windows box, I ran the
> : following script:
> : open FILE1, "Perfect.xls" or die "Cannot open file: $!";
> :
> : my @stuff = stat "FILE1";
> :
> : print "@stuff";
> :
> : Unfortunately, I don't know why this never returned any values into
> : my @stuff variable.
>
> Because stat() works on filenames, not file handles.
Untrue.
perldoc -f stat
stat FILEHANDLE
stat EXPR
stat Returns a 13-element list giving the status info for
a file, either the file opened via FILEHANDLE, or
named by EXPR.
>
> my @stuff = stat 'Perfect.xls';
or:
my @stuff = stat FILE1; # *not* stat "FILE1". Big difference.
> : system ("copy FILE1 FILE2");
> :
> : close FILE1;
> : close FILE2;
>
> use File::Copy 'copy';
>
> copy( 'Perfect.xls', 'folder/Perfect.xls') or die "Copy failed: $!";
Typing a hardcoded string more often than is necessary is a sure way to
introduce typos
copy ('Perfect.xls', 'folder/') or die "Copy failed: $!";
Paul Lalli
| |
| Adedayo Adeyeye 2005-12-14, 6:56 pm |
| Thanks Charles.
The copy parts works great. However, I still can't get any information on
the file. No values are being returned. I did the following:
use File::stat;
($dev, $ino, $mode, $nlink, $uid, $gid, $rdev, $size, $atime, $mtime,
$ctime, $blksize, $blocks)=stat("Perfect.xls");
print "$atime";
print "$mtime";
Kind regards
Dayo
-----Original Message-----
From: Charles K. Clarkson [mailto:cclarkson@htcomp.net]
Sent: Wednesday, December 14, 2005 6:28 PM
To: 'Perl Beginners - CGI List'
Subject: RE: Backing Up Files to a Remote Server
Adedayo Adeyeye <mailto:a.adeyeye@netcomng.com> wrote:
: Thanks.
:
: To get the statistics of a file on my windows box, I ran the
: following script:
:
:
: open FILE1, "Perfect.xls" or die "Cannot open file: $!";
:
: my @stuff = stat "FILE1";
:
: print "@stuff";
:
: Unfortunately, I don't know why this never returned any values into
: my @stuff variable.
Because stat() works on filenames, not file handles.
my @stuff = stat 'Perfect.xls';
: Next I tried this:
:
: open FILE1, "Perfect.xls" or die "Cannot open file: $!";
:
: open FILE2, ">folder\Perfect.xls" or die "Cannot write to destination
: directory: $!";
In perl, directories are separated by "/" not "\". "\P" is an
escaped "P".
: system ("copy FILE1 FILE2");
:
: close FILE1;
: close FILE2;
use File::Copy 'copy';
copy( 'Perfect.xls', 'folder/Perfect.xls') or die "Copy failed: $!";
HTH,
Charles K. Clarkson
--
Mobile Homes Specialist
254 968-8328
--
To unsubscribe, e-mail: beginners-cgi-unsubscribe@perl.org
For additional commands, e-mail: beginners-cgi-help@perl.org
<http://learn.perl.org/> <http://learn.perl.org/first-response>
| |
| Paul Lalli 2005-12-14, 6:56 pm |
| Adedayo Adeyeye wrote:
> Thanks Charles.
>
> The copy parts works great. However, I still can't get any information on
> the file. No values are being returned. I did the following:
>
> use File::stat;
>
> ($dev, $ino, $mode, $nlink, $uid, $gid, $rdev, $size, $atime, $mtime,
> $ctime, $blksize, $blocks)=stat("Perfect.xls");
You are confusing the two different uses of stat().
If you use the File::stat module, stat() is overwritten to return a
single object which contains all the properties, not a list of
individual elements.
my $obj = stat('Perfect.xls');
> print "$atime";
> print "$mtime";
print "Atime: ", $stat->atime, "\n";
print "Mtime: ", $stat->mtime, "\n";
If you want to use the 13 element list, remove the
use File::stat;
line, to use the normal, built-in version of stat.
For more information:
perldoc -f stat
Paul Lalli
| |
| Adedayo Adeyeye 2005-12-14, 6:56 pm |
| Thanks Dwalu.
Still didn't work. However, I removed use File::stat and everything works
fine now.
Kind regards
Dayo
-----Original Message-----
From: Dwalu Z. Khasu [mailto:dwalu@cs.bu.edu]
Sent: Wednesday, December 14, 2005 8:08 PM
To: Adedayo Adeyeye
Cc: 'Charles K. Clarkson'; 'Perl Beginners - CGI List'
Subject: RE: Backing Up Files to a Remote Server
On Wed, 14 Dec 2005, Adedayo Adeyeye wrote:
=>Thanks Charles.
=>
=>The copy parts works great. However, I still can't get any information on
=>the file. No values are being returned. I did the following:
=>
=>use File::stat;
=>
=>($dev, $ino, $mode, $nlink, $uid, $gid, $rdev, $size, $atime, $mtime,
=>$ctime, $blksize, $blocks)=stat("Perfect.xls");
=>
=>print "$atime";
=>print "$mtime";
=>
=>Kind regards
=>
=>Dayo
=>
Dayo,
Use the fully qualified path. Eg. "/home/dayo/test/Perfect.xls". The
code above looks good, except that you don't seem to be using the 'strict'
pragma or lexical variable declarations using 'my'.
See also:
perldoc strict
perldoc -f my
--
- Dwalu
..peace
--
I am an important person in this world -
Now is the most important time in my life -
My mistakes are my best teachers -
So I will be fearless.
- Student Creed
| |
| Charles K. Clarkson 2005-12-14, 6:56 pm |
| Adedayo Adeyeye <mailto:a.adeyeye@netcomng.com> wrote:
: Still didn't work. However, I removed use File::stat and everything
: works fine now.
IIRC, File::stat is an OO version of stat(). I believe it forces
stat() to return a hash or a blessed object, not an array.
: =>print "$atime";
: =>print "$mtime";
Why are $atime and $mtime in quotes? Read perlfaq4:
What's wrong with always quoting "$vars"?
HTH,
Charles K. Clarkson
--
Mobile Homes Specialist
254 968-8328
| |
| Dwalu Z. Khasu 2005-12-14, 6:56 pm |
| On Wed, 14 Dec 2005, Adedayo Adeyeye wrote:
=>Thanks Charles.
=>
=>The copy parts works great. However, I still can't get any information on
=>the file. No values are being returned. I did the following:
=>
=>use File::stat;
=>
=>($dev, $ino, $mode, $nlink, $uid, $gid, $rdev, $size, $atime, $mtime,
=>$ctime, $blksize, $blocks)=stat("Perfect.xls");
=>
=>print "$atime";
=>print "$mtime";
=>
=>Kind regards
=>
=>Dayo
=>
Dayo,
Use the fully qualified path. Eg. "/home/dayo/test/Perfect.xls". The
code above looks good, except that you don't seem to be using the 'strict'
pragma or lexical variable declarations using 'my'.
See also:
perldoc strict
perldoc -f my
--
- Dwalu
..peace
--
I am an important person in this world -
Now is the most important time in my life -
My mistakes are my best teachers -
So I will be fearless.
- Student Creed
| |
| Dwalu Z. Khasu 2005-12-14, 9:55 pm |
| On Wed, 14 Dec 2005, Adedayo Adeyeye wrote:
=>Thanks Dwalu.
=>
=>Still didn't work. However, I removed use File::stat and everything works
=>fine now.
=>
=>Kind regards
=>
=>Dayo
=>
Apologies Dayo. I took a quick glance and missed the 'use File::stat'.
Here's the quick explanation of what was happening:
perl provides a builtin function, stat, that returns a list of file
information so your original line of
==>($dev, $ino, $mode, $nlink, $uid, $gid, $rdev, $size, $atime, $mtime,
==>$ctime, $blksize, $blocks)=stat("Perfect.xls");
would have worked just fine on its own. (As you've just found out)
The module, File::stat, overrides (replaces) perl's core function with one
that returns an object so you'd need something like:
use File::stat;
my $fs = stat($filename);
print $fs->atime;
print $fs->mtime;
I hope that makes sense now and clears up the previous confusion but it's
much better explained via "perldoc File::stat".
--
- Dwalu
..peace
--
I am an important person in this world -
Now is the most important time in my life -
My mistakes are my best teachers -
So I will be fearless.
- Student Creed
|
|
|
|
|