Skip to content

Instantly share code, notes, and snippets.

@sangheonhan
Created January 11, 2019 07:09
Show Gist options
  • Save sangheonhan/99f73c22a3d910da2ee53e2fda8a3452 to your computer and use it in GitHub Desktop.
Save sangheonhan/99f73c22a3d910da2ee53e2fda8a3452 to your computer and use it in GitHub Desktop.
원격 Git 저장소들을 백업 목적으로 clone 또는 pull 하는 스크립트
#! /usr/bin/env perl
use strict;
use warnings;
use Git::Repository;
my $fh;
open $fh, '-|', 'ssh xen01vm02 ls /home/bookworm/git/' or die('Can\'t open remote git repository');
while ( my $dir = <$fh> ) {
chomp $dir;
if ( $dir =~ /.+\.git$/ ) {
my @dirname = split /\./, $dir;
print "> $dirname[0]\n";
unless ( -e $dirname[0] ) {
Git::Repository->run( clone => "ssh://xen01vm02/home/bookworm/git/$dir" );
next;
}
if ( -d $dirname[0] ) {
my $repo = Git::Repository->new( work_tree => $dirname[0] );
my @output = $repo->run(pull => '--all');
print "@output\n";
next;
}
}
print "skip.\n";
}
close $fh;
1;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment