Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??
    0: Just thought i would share this... i created it after
    1: finding not finding anything with this functionality
    2: (a while ago).  It was made for my personal needs 
    3: initially, and was doctored up a few weeks later to
    4: be somewhat customizable.  Its about a year old.
    5: 
    6: I have a cronjob that runs it every day:
    7: 0 1 * * * /home/conteb/cvs/snapshot.pl phynd /var/www/snapshots /var/cvs >> /var/www/snapshots/snapshots.log 2>&1
    8: 
    9: Sample can be found at http://www.phynd.net/snapshots/
    10: 
    11: #!/usr/bin/perl
    12: #
    13: # Create nightly cvs snapshots of project in a 
    14: # repository, only saving the snapshot if the module 
    15: # has changed.
    16: # 
    17: # TODO: Error checking is by no means complete.
    18: #
    19: use Date::Manip;
    20: 
    21: use strict;
    22: use warnings;
    23: 
    24: sub printHelp; # print basic help screen
    25: 
    26: my $tempdir = '/tmp/';
    27: my $maxdayspast = 90; # will only check 90 days in the past before recording.
    28: 
    29: # Can take 1 - 3 args - project name and dir to put resulting snapshot
    30: my $project = shift(@ARGV) or printHelp;
    31: my $dest = shift(@ARGV) or printHelp;
    32: my $server = shift(@ARGV) or printHelp;
    33: 
    34: 
    35: # test $tempdir, $dest for access and writabilty
    36: die "Error: No access to /tmp or /tmp not a dir\n"
    37:     unless (-w $tempdir && -d $tempdir);
    38: die "Error: No access to $dest, $dest not a dir, or $dest doen't exist\n"
    39:     unless (-d $dest && -w $dest);
    40: 
    41: 
    42: # First checkout the needed cvs directory
    43: chdir $tempdir;
    44: if (defined $server) {
    45:     (`cvs -d $server co -P $project 2>&1`=~/cannot find module/) and 
    46: 	die "Error: Invalid project specified - could not find module\n";
    47: }
    48: 
    49: # get todays date and adjust acordingly...
    50: my $date=$1 if &ParseDate('today')=~/(\d{8})/;
    51: 
    52: # create tarball
    53: `tar czf $dest/$project-$date.tar.gz $project`;
    54: 
    55: # Now, find the last tarball
    56: my $prev=1;
    57: my $filename;
    58: do {
    59:     &DateCalc($date, "-".$prev." days")=~/(\d{8})/;
    60:     $filename=$dest.'/'.$project."-".$1.".tar.gz";
    61:     $prev++;
    62: } while ((!(-e $filename))&&($prev < $maxdayspast));
    63: 
    64: # for some reason, compressed tarballs of identical trees checked out
    65: # at different times create slightly different sized tarballs (on my 
    66: # machine, anyway, using reiserfs).  I'm not about to step out of my 
    67: # league and try to explain it - but it means we have to untar the package
    68: # and run a diff on the two trees to see if there is a difference.
    69: if ($prev == $maxdayspast) {
    70:     print "Did not find any snapshots within $maxdayspast days, recording new..."; }
    71: else {
    72:     `mv $project $project.new`;
    73:     `tar xzvf $filename `;
    74:     if (`diff -Naur $project $project.new`) {
    75: 	print "Changes detected, recording snapshot...";
    76:     }
    77:     else {
    78: 	`rm $dest/$project-$date.tar.gz`; # dont save if nothing changed
    79:     }
    80:     `rm -r $project.new`;
    81: }
    82: 
    83: # remove project directories
    84: `rm -r $project`;
    85: print "Done ($date)\n";
    86: exit;
    87: 
    88: sub printHelp {
    89:     print "Usage: snapshot.pl project destination_dir server\n";
    90:     print "  project           name of project to check out of cvs\n";
    91:     print "  destination_dir   where to put the snapshot\n";
    92:     print "  server            server to connect to.  used as cvs -d server...\n";
    93:     exit;
    94: }

In reply to Creating Neat CVS snapshots... by cyberconte

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!
  • 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, 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, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            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.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others wandering the Monastery: (5)
    As of 2014-07-13 15:32 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      When choosing user names for websites, I prefer to use:








      Results (250 votes), past polls