diff options
author | Richard Ipsum <richard.ipsum@codethink.co.uk> | 2013-12-10 17:46:57 +0000 |
---|---|---|
committer | Richard Ipsum <richard.ipsum@codethink.co.uk> | 2013-12-17 15:19:38 +0000 |
commit | c0be9a2dd38fa73e2b0f0958361fd3a1234d3f01 (patch) | |
tree | 1c97e2d53fdad3f9f7f3de8dbddb017b81367a46 | |
parent | 17936a0dc7d75eb1e93a37bcf5959f03add53c10 (diff) | |
download | lorry-c0be9a2dd38fa73e2b0f0958361fd3a1234d3f01.tar.gz |
Modify lorry backup behaviour and rename tests
-rwxr-xr-x | lorry | 51 | ||||
-rwxr-xr-x | tests/git-backup-on-error-multiple-backups.script (renamed from tests/git-backup-on-error.script) | 4 | ||||
-rwxr-xr-x | tests/git-backup-on-error-multiple-backups.setup (renamed from tests/git-backup-on-error.setup) | 0 | ||||
-rw-r--r-- | tests/git-backup-on-error-multiple-backups.stderr (renamed from tests/git-backup-on-error.stderr) | 0 | ||||
-rw-r--r-- | tests/git-backup-on-error-multiple-backups.stdout (renamed from tests/git-backup-on-error.stdout) | 0 |
5 files changed, 36 insertions, 19 deletions
@@ -89,6 +89,9 @@ class Lorry(cliapp.Application): self.settings.string(['tarball-dest'], 'put created tarballs in TARBALLS', metavar='TARBALLS') + self.settings.boolean(['keep-multiple-backups'], + 'keep multiple (time-stamped) backups (disabled by default)', + default=False) def process_args(self, args): status = 0 @@ -189,7 +192,31 @@ class Lorry(cliapp.Application): if not os.path.exists(dirname): os.mkdir(dirname) gitdir = os.path.join(dirname, 'git') - backupdir = self.backup_gitdir(name, dirname, gitdir) + + time = datetime.now().strftime('%F-%T') + + pre_update_name = 'git-pre-update' + pre_update_backup_suffix = (pre_update_name + '-' + time + if self.settings['keep-multiple-backups'] else pre_update_name) + + pre_update_backup_dir = os.path.join(dirname, pre_update_backup_suffix) + + post_fail_name = 'git-post-fail' + post_fail_backup_suffix = (post_fail_name + '-' + time + if self.settings['keep-multiple-backups'] else post_fail_name) + + post_fail_backup_dir = os.path.join(dirname, post_fail_backup_suffix) + + if not self.settings['keep-multiple-backups']: + # remove previous backups if they exist + if os.path.exists(pre_update_backup_dir): + shutil.rmtree(pre_update_backup_dir) + + if os.path.exists(post_fail_backup_dir): + shutil.rmtree(post_fail_backup_dir) + + backupdir = self.backup_gitdir(name, gitdir, pre_update_backup_dir) + try: self.needs_aggressive = False table[vcstype](name, dirname, gitdir, spec) @@ -206,8 +233,8 @@ class Lorry(cliapp.Application): self.make_tarball(name, gitdir) except: if backupdir is not None: - faildir = self.save_failgit(name, dirname, gitdir) - self.restore_backup(name, dirname, gitdir, backupdir) + faildir = self.backup_gitdir(name, gitdir, post_fail_backup_dir) + self.restore_backup(name, backupdir, gitdir) self.output.write('Mirror of %s failed, state before mirror ' 'is saved at %s and state after mirror is ' 'saved at %s\n' % (name, backupdir, faildir)) @@ -226,7 +253,7 @@ class Lorry(cliapp.Application): self.progress('.. removing %s git repository backup' % name) shutil.rmtree(backupdir) - def restore_backup(self, name, dirname, gitdir, backupdir): + def restore_backup(self, name, backupdir, gitdir): self.progress('.. restoring %s good git repository' % name) dotgit = os.path.join(gitdir, '.git') if not os.path.exists(dotgit): @@ -234,23 +261,13 @@ class Lorry(cliapp.Application): shutil.rmtree(dotgit) self.copy_gitdir(backupdir, dotgit) - def save_failgit(self, name, dirname, gitdir): - self.progress('.. saving failed %s mirror git repository' % name) + def backup_gitdir(self, name, gitdir, backupdir): dotgit = os.path.join(gitdir, '.git') if not os.path.exists(dotgit): dotgit = gitdir - time = datetime.now().strftime('%F-%T') - backupdir = os.path.join(dirname, "git-post-fail-%s" % time) - return self.copy_gitdir(dotgit, backupdir) - def backup_gitdir(self, name, dirname, gitdir): - dotgit = os.path.join(gitdir, '.git') - if not os.path.exists(dotgit): - dotgit = gitdir - time = datetime.now().strftime('%F-%T') - backupdir = os.path.join(dirname, "git-pre-update-%s" % time) - self.progress('.. backing up %s git repository to %s' % - (name, backupdir)) + self.progress('.. backing up %s git repository to %s' % (name, backupdir)) + return self.copy_gitdir(dotgit, backupdir) def copy_gitdir(self, source, dest): diff --git a/tests/git-backup-on-error.script b/tests/git-backup-on-error-multiple-backups.script index 544a392..8bda5ad 100755 --- a/tests/git-backup-on-error.script +++ b/tests/git-backup-on-error-multiple-backups.script @@ -42,8 +42,8 @@ normalize() { # make upstream disappear to cause errors rm -rf "$repo" if "${SRCDIR}/test-lorry" --pull-only --log="$logfile" --working-area="$workdir" \ - "$DATADIR/git-backup-test-repo.lorry" --bundle=never 2>/dev/null | \ - normalize + "$DATADIR/git-backup-test-repo.lorry" --bundle=never 2>/dev/null \ + --keep-multiple-backups | normalize then echo Previous lorry command should have failed >&2 exit 1 diff --git a/tests/git-backup-on-error.setup b/tests/git-backup-on-error-multiple-backups.setup index 03a8dad..03a8dad 100755 --- a/tests/git-backup-on-error.setup +++ b/tests/git-backup-on-error-multiple-backups.setup diff --git a/tests/git-backup-on-error.stderr b/tests/git-backup-on-error-multiple-backups.stderr index e69de29..e69de29 100644 --- a/tests/git-backup-on-error.stderr +++ b/tests/git-backup-on-error-multiple-backups.stderr diff --git a/tests/git-backup-on-error.stdout b/tests/git-backup-on-error-multiple-backups.stdout index d918599..d918599 100644 --- a/tests/git-backup-on-error.stdout +++ b/tests/git-backup-on-error-multiple-backups.stdout |