#!/bin/perl use warnings; use strict; use File::Find; use Archive::Tar; # Directory to begin search files our $directoriesToSearch = '/internal/'; # Directory to hold backups our $backupLocation = '/ipbackups/'; # Calculate current date for use in archive filename my ($day,$month,$year) = (localtime(time))[3,4,5]; $year += 1900; $month++; # Archive filename our $backupFilename = "backup_$month-$day-$year.tar.gz"; # Array to hold files to be backed up our @filesToBackup; # Array holding directories to be skipped our @directoriesToSkip = qw{ /internal/scripts/chatlog /internal/scripts/schedule }; # Array holding extensions to backup our @extensionsToBackup = qw{cgi pl dat txt log}; # Let the user know what we're doing and begin finding files. print "Find files for backup..."; find(\&actOnFiles,($directoriesToSearch)); # Notify the user that the find process is done and that we're # creating the archive. Then, create the archive. print "Done!\nCreating archive $backupFilename..."; Archive::Tar->create_archive ("$backupLocation$backupFilename", 9, @filesToBackup); # Notify the user and exit. print "Done!\n"; sub actOnFiles() { # Check if the file is in a skipped directory and, if so, # return without action foreach my $dir (@directoriesToSkip){ return if ($File::Find::dir =~ m/$dir/); } # Check if the file has an appropriate extension. If not, # return without action my $test = join('|',@extensionsToBackup); return unless ($_ =~ m/.($test)$/i); # Fail-safe check to make sure a directory hasn't slipped through return if (-d $File::Find::name); # Assuming the file has survived this long, push it into the # list of files to backup. push(@filesToBackup,$File::Find::name); }

In reply to Create Daily Backups of Scripts and Datafiles Inside a Web Site by jpfarmer

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.