From 5d5045bcb450421363a0d2421435371ff02c631f Mon Sep 17 00:00:00 2001 From: Sean Whitton Date: Thu, 8 Sep 2022 16:46:54 -0700 Subject: locmaint: pair athpriv.git backup with ~/src/athpriv --- bin/locmaint | 46 ++++++++++++++++++++++++++++++++-------------- 1 file changed, 32 insertions(+), 14 deletions(-) (limited to 'bin') diff --git a/bin/locmaint b/bin/locmaint index 750e5628..94c2e2de 100755 --- a/bin/locmaint +++ b/bin/locmaint @@ -94,12 +94,17 @@ our $check_for_extdrive = 0; # remote server with a git-annex branch, which are not listed here, # will be backed up as if they were just ordinary git repos. That's # desirable behaviour for some annexes, which is why we don't try to -# autodetect them +# autodetect them. +# +# synconlyannex refers to the annex.synconlyannex config key; see +# git-annex-config(1). We hardcode this here so that we can know how to clone +# an annex as part of backing it up even when there's no clone in HOME. our @remote_annexes = ( { origin => "athenag:annex.git", homedir => "lib/annex", lazy => 1 }, { origin => "athenag:annex19.git", homedir => "annex" }, { origin => "athenag:libpriv.git", homedir => "lib/priv" }, - { origin => "athena:wikiannex", homedir => "lib/wikiannex" }); + { origin => "athena:wikiannex", homedir => "lib/wikiannex" }, + { origin => "athenap:athpriv", homedir => "src/athpriv", synconlyannex => 1 }); for (getpwuid($<) . '@' . `hostname -f`) { chomp; @@ -727,10 +732,11 @@ C should ensure it's available. sub backup_repo { my ($uri, $dest) = @_; - my ($paired_annex, $lazy_paired_annex) - = map { (catfile($ENV{HOME}, $_->{homedir}), $_->{lazy} // 0) } - grep { $_->{origin} eq $uri } @remote_annexes; + my ($paired_annex, $lazy_paired_annex, $synconlyannex) + = map +(catfile($ENV{HOME}, $_->{homedir}), $_->{lazy}, + $_->{synconlyannex}), grep $_->{origin} eq $uri, @remote_annexes; $dest = "$dest.git" unless $dest =~ /\.git\z/; + my $do_origin_fetch = !$paired_annex || $synconlyannex; # when we are backing up a paired annex, we need to be on a # removable drive under /media, because that's going to be the @@ -767,7 +773,7 @@ sub backup_repo { make_path($dest) unless -d $dest; # bare repos don't get a reflog by default system "git -C $dest -c core.logAllRefUpdates=true clone " - . (defined $paired_annex ? "--bare" : "--mirror") . " $uri ."; + . ($do_origin_fetch ? "--mirror" : "--bare") . " $uri ."; } my $git = Git::Wrapper->new($dest); @@ -796,6 +802,13 @@ sub backup_repo { $git->config(qw(annex.diskreserve 2GB)); $git->annex(qw(wanted . standard)); $git->annex(qw(group . incrementalbackup)); + if ($synconlyannex) { + system "git", "branch", "-D", "git-annex"; + $git->config("--add", "remote.origin.fetch", + "^refs/heads/git-annex"); + $git->config("--add", "remote.origin.fetch", + "^refs/heads/synced/git-annex"); + } } if (-d catfile($paired_annex, ".git") && -d catfile($paired_annex, ".git", "annex")) { @@ -803,6 +816,7 @@ sub backup_repo { my @remotes = $pair->remote(); $pair->remote("add", $desc, $dest) unless (grep /^$desc$/, @remotes); + $synconlyannex and $git->config("annex.synconlyannex", "true"); # bypass Git::Wrapper so that output is printed interactive_ensure_subroutine_success( sub { @@ -819,9 +833,13 @@ sub backup_repo { . " on this machine, so not updating $dest"); get_ack(); } - } elsif (!$clone_needed - # additional check to avoid accidental ref clobbering - and !-d catfile($dest, ".git", "annex")) { + } + if ( + $do_origin_fetch + and !$clone_needed + # additional check to avoid accidental ref clobbering + and ($synconlyannex or !-d catfile($dest, ".git", "annex")) + ) { my ($origin) = $git->config(qw(remote.origin.url)); die "$dest has origin remote URI $origin but we expected $uri" @@ -835,13 +853,13 @@ sub backup_repo { || ("$origin $uri" =~ m|gcrypt::rsync://athena:/srv/gcrypt/(.+) athenag:\1|); + my $fetch = "--tags --no-prune +refs/heads/*:refs/heads/*"; + $synconlyannex + and $fetch .= " ^refs/heads/git-annex ^refs/heads/synced/git-annex"; + # bypass Git::Wrapper so that fetch output is shown to the user interactive_ensure_subroutine_success( - sub { - system_pty_capture( -"git -C $dest fetch origin +refs/heads/*:refs/heads/* --tags --no-prune" - ); - }); + sub { system_pty_capture "git -C $dest fetch origin $fetch" }); } } -- cgit v1.2.3