This is the script that I install on a USB thumb drive that performs a backup of some data from my computer. This script just performs back ups of various git repositories on my computer.

It uses bare repositories so that the backups are valid on vfat filesystems.

This script is used as part of by backup to USB drive scheme described here:

Encrypted backups on USB drives using truecrypt, ivman and hal

#!/usr/bin/perl

$root = $ENV{ "HOME" };
$mntpoint = $ARGV[0];

@repDirs = ( "$root/project" );
@reps = ( "$root/bin", "$root/thesis" );

foreach $dir ( @repDirs )
{
    getReps( $root, "$root/project" );
}

foreach $rep ( @reps )
{
    getRep( $root, $rep );
}

sub repToLocal($$)
{
    my ($root,$rep) = @_;
    $rep =~ s/$root/$mntpoint/;
    return $rep;
}

sub getReps ($$)
{
    my ($root, $dir) = @_;
    my (@reps,$rep);

    @reps = `find $dir -name ".git"`;

    foreach $rep ( @reps )
    {
        chomp( $rep );
        $rep =~ s/\/\.git//;

        getRep( $root, $rep );
    }
}

sub getRep($$)
{
    my ($root, $rep) = @_;
    my ($local,$cmd);

    $local = repToLocal( $root, $rep );

    if ( -d $local )
    {
        print "updating $rep\n";
        $cmd = "cd $rep && git push $local\n";
    }
    else
    {
        print "cloning $rep\n";
        $cmd = "git clone -l --bare $rep $local\n";
    }

    `$cmd`;
}

Retrieved from "http://www.floccinaucinihilipilification.net/wiki/index.php/Git_repository_backup_script"

This page has been accessed 555 times. This page was last modified 23:25, 8 July 2007.