Ojas has asked for the wisdom of the Perl Monks concerning the following question:

Dear Monks, Season's wishes. I am trying for a simple script which will: a) Take backup base directory and list of from command line. b) Create backup base directory and copy files into it Problem statement: 1) system ($CP, $srcfile, $dstfile) doesn't work.

if($file =~ m/\.txt$/i){ #backup to $BACKUP_BASE_DIR $dstDir = $BACKUP_BASE_DIR.$myDir; system("/bin/mkdir -p -m 755 $dstDir"); system(`/bin/cp -p $currentFile $dstDir`); print "$CP $currentFile $dstDir"; print "\n"; } else{}

Replies are listed 'Best First'.
Re: Dynamic Backup script
by stonecolddevin (Parson) on Dec 23, 2013 at 21:28 UTC

    Just use rsync. It's going to do what you're trying to do a lot better and faster.

    Three thousand years of beautiful tradition, from Moses to Sandy Koufax, you're god damn right I'm living in the fucking past

Re: Dynamic Backup script
by ww (Archbishop) on Dec 23, 2013 at 19:09 UTC

    We can offer more and better help if you provide us with a precise and detailed translation of "doesn't work."

    The Monastery's crystal ball has been out of service for some time. It doesn't work.

    Update and PS: I don't see a statement in the form which appears in your narrative, system ($CP, $srcfile, $dstfile); an instantiation of $CP, nor any reason to surround the CLI in Ln7 with backticks (`) since you've invoked system. Since you've created an ID/handle and account, you can edit your OP... but please include a note identifying what you've changed, added, deleted or otherwise amended.