You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@subversion.apache.org by Jani Averbach <ja...@cc.jyu.fi> on 2002/12/13 22:54:14 UTC

[PATCH] Allow to made multible backup from same version

Hi!

log:

If you want like use the hot-backup.py like generic hot-backup utility,
(and not only by post-commit hook), it might be feasible that you would
made multible backup of same revision.

This pacth take care of this case.

* tools/backup/hot-backup.py: modified

BR, Jani

Index: tools/backup/hot-backup.py
===================================================================
--- tools/backup/hot-backup.py	(revision 4111)
+++ tools/backup/hot-backup.py	(working copy)
@@ -77,6 +77,15 @@
 # Step 2:  copy the whole repository structure.

 backup_subdir = os.path.join(backup_dir, repo + "-" + youngest)
+
+# if there is backup already, add additional
+# increment at the end of path
+try_count = 1
+while os.path.exists(backup_subdir):
+   backup_subdir = os.path.join(backup_dir, repo + "-" + youngest + "-" + `try_count`)
+   try_count += 1
+
+
 print "Backing up repository to '" + backup_subdir + "'..."
 shutil.copytree(repo_dir, backup_subdir)
 print "Done."
@@ -159,9 +168,19 @@

 # Step 8:  finally, remove the repository back that's NUM_BACKUPS older
 # than the one we just created.
+# If there are multible versions of this rep. backup, remove them also

 kill_rev = int(youngest) - num_backups
 old_backup_subdir = os.path.join(backup_dir, repo + "-" + `kill_rev`)
 if os.path.exists(old_backup_subdir):
   print "Removing old backup: " + old_backup_subdir
   shutil.rmtree(old_backup_subdir)
+  try_count = 1
+  old_backup_subdir = os.path.join(backup_dir, repo + "-" + `kill_rev` + "-" + `try_count`)
+  while os.path.exists(old_backup_subdir):
+     print "Removing old backup: " + old_backup_subdir
+     shutil.rmtree(old_backup_subdir)
+     try_count += 1
+     old_backup_subdir = os.path.join(backup_dir, repo + "-" + `kill_rev` + "-" + `try_count`)
+
+


--
Jani Averbach


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org

Re: [PATCH] Allow to made multible backup from same version

Posted by Jani Averbach <ja...@cc.jyu.fi>.
On 15 Dec 2002, Philip Martin wrote:

> I don't understand why one would want multiple backups of the same
> revison, particularly if they are in directories with arbitrary names.
>

Good question. =)

But If I run manually hot-backup.py, I want that it will made a backup to
me, regardless if there is already one or not.

> However looking at the patch I see a race in the existing code when
> used a a post-commit hook.  A post-commit script runs asynchronously,
> so it cannot assume that the repository has not changed since the
> commit that triggered the script.  Consider the following
>
>   1. Commit X completes and triggers the 'X' run of the post-commit.
>   2. Commit Y completes and triggers the 'Y' run of the post-commit.
>   3. The 'X' post-commit starts.
>   4. The 'Y' post-commit starts.
>   5. The 'X' post-commit completes, but backs-up Y since that HEAD.
>   6. The 'Y' post-commit will now do
>        shutil.copytree(repo_dir, backup_subdir)
>      but backup_subdir already exists and contains a backup of Y.
>

So, the script should be modified to use passed new revision nro by
post-commit, at least? Then it would made backup of wrong version, but it
will not fail.

Is this the only solution? IMHO, it would not made sense block incoming
commits during backup operation. Is there even any way to do this?

There is no way to made hot-backup of spesified version, isn't?


BR, Jani

--
Jani Averbach





---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org

Re: [PATCH] Allow to made multible backup from same version

Posted by Philip Martin <ph...@codematters.co.uk>.
Karl Fogel <kf...@newton.ch.collab.net> writes:

> > Index: tools/backup/hot-backup.py
> > ===================================================================
> > --- tools/backup/hot-backup.py	(revision 4111)
> > +++ tools/backup/hot-backup.py	(working copy)
> > @@ -77,6 +77,15 @@
> >  # Step 2:  copy the whole repository structure.
> > 
> >  backup_subdir = os.path.join(backup_dir, repo + "-" + youngest)
> > +
> > +# if there is backup already, add additional
> > +# increment at the end of path
> > +try_count = 1
> > +while os.path.exists(backup_subdir):
> > +   backup_subdir = os.path.join(backup_dir, repo + "-" + youngest + "-" + `try_count`)
> > +   try_count += 1
> > +
> > +
> >  print "Backing up repository to '" + backup_subdir + "'..."
> >  shutil.copytree(repo_dir, backup_subdir)
> >  print "Done."

I don't understand why one would want multiple backups of the same
revison, particularly if they are in directories with arbitrary names.

However looking at the patch I see a race in the existing code when
used a a post-commit hook.  A post-commit script runs asynchronously,
so it cannot assume that the repository has not changed since the
commit that triggered the script.  Consider the following

  1. Commit X completes and triggers the 'X' run of the post-commit.
  2. Commit Y completes and triggers the 'Y' run of the post-commit.
  3. The 'X' post-commit starts.
  4. The 'Y' post-commit starts.
  5. The 'X' post-commit completes, but backs-up Y since that HEAD.
  6. The 'Y' post-commit will now do
       shutil.copytree(repo_dir, backup_subdir)
     but backup_subdir already exists and contains a backup of Y.

-- 
Philip Martin

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org

RE: [PATCH] Allow to made multible backup from same version

Posted by Jani Averbach <ja...@cc.jyu.fi>.
On Mon, 16 Dec 2002, Sander Striker wrote:

>
> Still Philips question wasn't answered.  Like him I don't see why you'd
> want to make multiple backups of the same rev like this.  Could you explain
> your use case first?
>

My previous post:
>> Good question. =)
>>
>> But If I run manually hot-backup.py, I want that it will made a backup
>> to me, regardless if there is already one or not.

One solution would be that we combine two cases: my orginal and solution
for Philip's race situation by patch that changes hot-backup.py's command
line arguments count.

If there is additional (optional) argument for backup's dir. postfix, then
the problem fade a way. User could made unique name, and post-commit hook
could give a revision number as an argument, and then backups will have
unique name in the race case.


If I could convince you that this feature is acceptable, I will produce
new patch with good log.


BR, Jani

--
Jani Averbach




---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org

RE: [PATCH] Allow to made multible backup from same version

Posted by Sander Striker <st...@apache.org>.
> From: Karl Fogel [mailto:kfogel@newton.ch.collab.net]
> Sent: Monday, December 16, 2002 3:56 AM

> Jani Averbach <ja...@cc.jyu.fi> writes:
>> Hmm, that is not the case, the original post was like that:
>> 
>>>> log:
>>>>
>>>> If you like to use the hot-backup.py like generic hot-backup utility,
>>>> (and not only by post-commit hook), it might be feasible that you could
>>>> made multible backup of same revision.

Still Philips question wasn't answered.  Like him I don't see why you'd
want to make multiple backups of the same rev like this.  Could you explain
your use case first?

Thanks,

Sander

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org

Re: [PATCH] Allow to made multible backup from same version

Posted by Karl Fogel <kf...@newton.ch.collab.net>.
Jani Averbach <ja...@cc.jyu.fi> writes:
> Hmm, that is not the case, the original post was like that:
> 
> >> log:
> >>
> >> If you like to use the hot-backup.py like generic hot-backup utility,
> >> (and not only by post-commit hook), it might be feasible that you could
> >> made multible backup of same revision.
> >>
> >> This pacth take care of this case.
> >>
> >> * tools/backup/hot-backup.py: modified
> >>
> 
> I combined by sneaky way the descriptive part of post and log message.
> Sorry about confusing.

I see :-).  The log message needs to say what changed, though.  I
don't just mean what symbols were affected, but also how did the
script's behavior change.  From the log message above, the reader
can't really tell what's different after this change.  (At least, this
reader can't.)

-K

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org

Re: [PATCH] Allow to made multible backup from same version

Posted by Jani Averbach <ja...@cc.jyu.fi>.
On 15 Dec 2002, Karl Fogel wrote:

> Jani Averbach <ja...@cc.jyu.fi> writes:
> > * tools/backup/hot-backup.py: modified
>
> I think you might have sent this before finishing the log message,
> Jani...
>

Hmm, that is not the case, the original post was like that:

>> log:
>>
>> If you like to use the hot-backup.py like generic hot-backup utility,
>> (and not only by post-commit hook), it might be feasible that you could
>> made multible backup of same revision.
>>
>> This pacth take care of this case.
>>
>> * tools/backup/hot-backup.py: modified
>>

I combined by sneaky way the descriptive part of post and log message.
Sorry about confusing.

BR, Jani

--
Jani Averbach



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org

Re: [PATCH] Allow to made multible backup from same version

Posted by Karl Fogel <kf...@newton.ch.collab.net>.
Jani Averbach <ja...@cc.jyu.fi> writes:
> * tools/backup/hot-backup.py: modified

I think you might have sent this before finishing the log message,
Jani...

-Karl


> BR, Jani
> 
> Index: tools/backup/hot-backup.py
> ===================================================================
> --- tools/backup/hot-backup.py	(revision 4111)
> +++ tools/backup/hot-backup.py	(working copy)
> @@ -77,6 +77,15 @@
>  # Step 2:  copy the whole repository structure.
> 
>  backup_subdir = os.path.join(backup_dir, repo + "-" + youngest)
> +
> +# if there is backup already, add additional
> +# increment at the end of path
> +try_count = 1
> +while os.path.exists(backup_subdir):
> +   backup_subdir = os.path.join(backup_dir, repo + "-" + youngest + "-" + `try_count`)
> +   try_count += 1
> +
> +
>  print "Backing up repository to '" + backup_subdir + "'..."
>  shutil.copytree(repo_dir, backup_subdir)
>  print "Done."
> @@ -159,9 +168,19 @@
> 
>  # Step 8:  finally, remove the repository back that's NUM_BACKUPS older
>  # than the one we just created.
> +# If there are multible versions of this rep. backup, remove them also
> 
>  kill_rev = int(youngest) - num_backups
>  old_backup_subdir = os.path.join(backup_dir, repo + "-" + `kill_rev`)
>  if os.path.exists(old_backup_subdir):
>    print "Removing old backup: " + old_backup_subdir
>    shutil.rmtree(old_backup_subdir)
> +  try_count = 1
> +  old_backup_subdir = os.path.join(backup_dir, repo + "-" + `kill_rev` + "-" + `try_count`)
> +  while os.path.exists(old_backup_subdir):
> +     print "Removing old backup: " + old_backup_subdir
> +     shutil.rmtree(old_backup_subdir)
> +     try_count += 1
> +     old_backup_subdir = os.path.join(backup_dir, repo + "-" + `kill_rev` + "-" + `try_count`)
> +
> +
> 
> 
> --
> Jani Averbach
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
> For additional commands, e-mail: dev-help@subversion.tigris.org

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org