CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Intermediate:
Problem with Backup Script

 



Shazer2
Novice

Jul 30, 2010, 9:58 PM

Post #1 of 13 (1584 views)
Problem with Backup Script Can't Post

Alright so I designed a backup script but it displays an error when trying to be run.

The error is: Unrecognized character /XA0; Marked by <-- HERE after <-- HERE near column 1 at filebackup.pl line 10.

The code I am using is:

Code
use strict; 
use warnings;

my $startDir = 'C:\Documents and Settings\Shannon\Desktop\SETUPS AND FILES';
my $newDir = 'G:\BACKUP';

myReadDir($startDir);

sub myReadDir {
   my($dir) = @_;
   opendir (DIR, $dir);
   my @dir = readdir (DIR);
   closedir(DIR);
   foreach my $file (@dir)  {
      next if ($file eq '.' or $file eq '..');
      if (-d $file) {
         print "$file is a directory\n";
         myReadDir("$dir/$file");
      }
   }            
}



FishMonger
Veteran / Moderator

Jul 31, 2010, 6:33 AM

Post #2 of 13 (1577 views)
Re: [Shazer2] Problem with Backup Script [In reply to] Can't Post

Use File::Find http://search.cpan.org/~jesse/perl-5.12.1/lib/File/Find.pm


Shazer2
Novice

Jul 31, 2010, 6:35 AM

Post #3 of 13 (1575 views)
Re: [FishMonger] Problem with Backup Script [In reply to] Can't Post

I want to stay with the original idea, and I just want to know what the problem is with it..


FishMonger
Veteran / Moderator

Jul 31, 2010, 6:58 AM

Post #4 of 13 (1568 views)
Re: [Shazer2] Problem with Backup Script [In reply to] Can't Post


In Reply To
I want to stay with the original idea

That would indicate to me that this is a requirement for a homework assignment.

Assuming that the code you posted is a copy/paste of your script and there is nothing else prior to that code, then line 10 would be:

Code
my($dir) = @_;

There is nothing wrong with that line and it would not generate the error you received.


FishMonger
Veteran / Moderator

Jul 31, 2010, 7:07 AM

Post #5 of 13 (1567 views)
Re: [Shazer2] Problem with Backup Script [In reply to] Can't Post

It is possible that the line has a non printable white space character which perl doesn't like. Try viewing the file with a hex editor, or simply backspace (delete) the leading characters to the point where it joins to the previous line. Then add back in the spaces.


(This post was edited by FishMonger on Jul 31, 2010, 7:07 AM)


Shazer2
Novice

Jul 31, 2010, 6:38 PM

Post #6 of 13 (1548 views)
Re: [Shazer2] Problem with Backup Script [In reply to] Can't Post

Well my friend is actually helping me with it, so i thought it would be a good idea to stay with the original code


FishMonger
Veteran / Moderator

Jul 31, 2010, 8:22 PM

Post #7 of 13 (1546 views)
Re: [Shazer2] Problem with Backup Script [In reply to] Can't Post

Does that mean that the problem is solved, or do you still need help?


Shazer2
Novice

Jul 31, 2010, 8:24 PM

Post #8 of 13 (1544 views)
Re: [Shazer2] Problem with Backup Script [In reply to] Can't Post

No my friend gave me that code, I still haven't solved it, please help! Or just supply me with a backup script which finds the original folder then saves in a different location. I need the code which I can just drop straight into Python and edit the locations. Thanks :P


FishMonger
Veteran / Moderator

Aug 1, 2010, 9:56 AM

Post #9 of 13 (1534 views)
Re: [Shazer2] Problem with Backup Script [In reply to] Can't Post


Quote
Or just supply me with a backup script which finds the original folder then saves in a different location.

You haven't provided enough info for anyone to be able to do that and we are here to assist you in troubleshooting your script. It's beyond the scope of this forum to provide complete custom scripts.

Based on the minimum program specs that you've given, I would not manually traverse and directory tree, especially not the way your friend coded it. Instead I'd use a utility that is designed for backing up directories. The first one that comes to mind, due to it's cross platform portability, is rsync. Perl has modules that interface with this utility. http://search.cpan.org/~leakin/File-Rsync-0.43/Rsync.pm

Another option, if you don't want to use external utilities, would be to use the File::Copy::Recursive module.
http://search.cpan.org/~dmuey/File-Copy-Recursive-0.38/Recursive.pm


Quote
I need the code which I can just drop straight into Python

What do you mean? Perl and Python are different languages with different syntax. You can't just drop one into the other.

Do you mean that you have a python script that will execute the perl script? If so, then that has no bearing on the Perl script or your base question/problem.


Shazer2
Novice

Aug 1, 2010, 11:18 PM

Post #10 of 13 (1517 views)
Re: [FishMonger] Problem with Backup Script [In reply to] Can't Post

My mistake I was meant to write Perl :S, sorry. I'm also just wondering whether or not it's possible or not for you to write a script in which you enter the folder you want backed up in a different location? Then it runs each time the computer is booted?


FishMonger
Veteran / Moderator

Aug 2, 2010, 9:31 AM

Post #11 of 13 (1479 views)
Re: [Shazer2] Problem with Backup Script [In reply to] Can't Post

Here's an example of one approach.


Code
#!/usr/bin/perl 

use strict;
use warnings;
use File::Copy::Recursive qw(dircopy);

my $startDir = 'C:\Documents and Settings\Shannon\Desktop\SETUPS AND FILES';
my $newDir = 'G:\BACKUP';

$File::Copy::Recursive::CPRFComp = 1;

dircopy($startDir, $newDir) or die $!;



Shazer2
Novice

Aug 2, 2010, 11:50 PM

Post #12 of 13 (1454 views)
Re: [FishMonger] Problem with Backup Script [In reply to] Can't Post

Well I tried that script it resulted in an error, as seen in the attachment.


Shazer2
Novice

Aug 3, 2010, 3:35 AM

Post #13 of 13 (1451 views)
Re: [Shazer2] Problem with Backup Script [In reply to] Can't Post

Everything solved thanks alot :)

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives