GNU bug report logs - #11809
document "So how do we just simply make a backup file?"

Previous Next

Package: coreutils;

Reported by: jidanni <at> jidanni.org

Date: Thu, 28 Jun 2012 15:36:02 UTC

Severity: normal

Tags: fixed

Done: Assaf Gordon <assafgordon <at> gmail.com>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 11809 in the body.
You can then email your comments to 11809 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-coreutils <at> gnu.org:
bug#11809; Package coreutils. (Thu, 28 Jun 2012 15:36:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to jidanni <at> jidanni.org:
New bug report received and forwarded. Copy sent to bug-coreutils <at> gnu.org. (Thu, 28 Jun 2012 15:36:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: jidanni <at> jidanni.org
To: bug-coreutils <at> gnu.org
Subject: document "So how do we just simply make a backup file?"
Date: Thu, 28 Jun 2012 23:30:59 +0800
(info "(coreutils) Backup options") should add some examples, for
"So how do we make a backup file of m?"
$ ls
m
$ cp -b m m #no go
$ cp m n
$ mv -b n m




Information forwarded to bug-coreutils <at> gnu.org:
bug#11809; Package coreutils. (Thu, 28 Jun 2012 16:06:02 GMT) Full text and rfc822 format available.

Message #8 received at 11809 <at> debbugs.gnu.org (full text, mbox):

From: Jim Meyering <jim <at> meyering.net>
To: jidanni <at> jidanni.org
Cc: 11809 <at> debbugs.gnu.org
Subject: Re: bug#11809: document "So how do we just simply make a backup file?"
Date: Thu, 28 Jun 2012 18:01:31 +0200
jidanni <at> jidanni.org wrote:
> (info "(coreutils) Backup options") should add some examples, for
> "So how do we make a backup file of m?"
> $ ls
> m
> $ cp -b m m #no go

Thanks for the suggestion.
I use this zsh/bash shell function:

backup ()
{
  local i
  for i in "$@"; do
    command cp -bf "$i" "$i"
  done
}

but as I inserted the above, I realize it's buggy.
It doesn't propagate failure like you'd expect,
so here's a better one:

backup()
{
  local i fail=0
  for i in "$@"; do
    command cp -bf -- "$i" "$i" || fail=1
  done
  return $fail
}

That's already almost what info coreutils says:

  Make a backup of each file that would otherwise be overwritten or removed.
  As a special case, @command{cp} makes a backup of @var{source} when the force
  and backup options are given and @var{source} and @var{dest} are the same
  name for an existing, regular file.  One useful application of this
  combination of options is this tiny Bourne shell script:

  @example
  #!/bin/sh
  # Usage: backup FILE...
  # Create a @sc{gnu}-style backup of each listed FILE.
  for i; do
    cp --backup --force -- "$i" "$i"
  done
  @end example

I'll adjust that to reflect the above improvement:
Do you think that's enough?

> $ cp m n
> $ mv -b n m




Information forwarded to bug-coreutils <at> gnu.org:
bug#11809; Package coreutils. (Thu, 28 Jun 2012 16:21:02 GMT) Full text and rfc822 format available.

Message #11 received at 11809 <at> debbugs.gnu.org (full text, mbox):

From: jidanni <at> jidanni.org
To: jim <at> meyering.net
Cc: 11809 <at> debbugs.gnu.org
Subject: Re: bug#11809: document "So how do we just simply make a backup file?"
Date: Fri, 29 Jun 2012 00:16:07 +0800
OK but (info "(coreutils) Backup options") should also link back to the exact
cp -b spot, else most folks will miss it.

P.S., There _is_ an easier way of making backups of several files,
But there is a bug, one has to do it one at a time despite -b. Bug bug bug. 

$ \cp -fb h k l .
cp: `h' and `./h' are the same file
cp: `k' and `./k' are the same file
cp: `l' and `./l' are the same file
$ \cp -fb h h
$




Information forwarded to bug-coreutils <at> gnu.org:
bug#11809; Package coreutils. (Fri, 29 Jun 2012 05:57:01 GMT) Full text and rfc822 format available.

Message #14 received at 11809 <at> debbugs.gnu.org (full text, mbox):

From: Jim Meyering <jim <at> meyering.net>
To: jidanni <at> jidanni.org
Cc: 11809 <at> debbugs.gnu.org
Subject: Re: bug#11809: document "So how do we just simply make a backup file?"
Date: Fri, 29 Jun 2012 07:52:00 +0200
jidanni <at> jidanni.org wrote:
> OK but (info "(coreutils) Backup options") should also link back to the exact
> cp -b spot, else most folks will miss it.
>
> P.S., There _is_ an easier way of making backups of several files,
> But there is a bug, one has to do it one at a time despite -b. Bug bug bug.
>
> $ \cp -fb h k l .
> cp: `h' and `./h' are the same file
> cp: `k' and `./k' are the same file
> cp: `l' and `./l' are the same file
> $ \cp -fb h h
> $

No, that was deliberate.

I deliberately restricted the "make backup only" functionality to the
very limited case that is documented.  Widening the semantics, as you
suggest above, seems like it would make this "feature" more likely to
be discovered accidentally -- with data loss, when both originals and
backups are removed.

If people think the make-backup-only feature is useful enough for
multiple files, then we can consider adding an --only-backup option,
(better name welcome, but it cannot start with "--backup") rather than
co-opting the --force --backup combination and requiring a script to
process more than one at a time.




Information forwarded to bug-coreutils <at> gnu.org:
bug#11809; Package coreutils. (Fri, 29 Jun 2012 08:17:01 GMT) Full text and rfc822 format available.

Message #17 received at 11809 <at> debbugs.gnu.org (full text, mbox):

From: jidanni <at> jidanni.org
To: jim <at> meyering.net
Cc: 11809 <at> debbugs.gnu.org
Subject: Re: bug#11809: document "So how do we just simply make a backup file?"
Date: Fri, 29 Jun 2012 16:11:45 +0800
JM> I deliberately restricted the "make backup only" functionality to the
JM> very limited case that is documented.
Well you had better explicitly document that it does not work with
all forms in the cp SYNOPSIS, else people will think it is broken...




Information forwarded to bug-coreutils <at> gnu.org:
bug#11809; Package coreutils. (Fri, 29 Jun 2012 08:53:02 GMT) Full text and rfc822 format available.

Message #20 received at 11809 <at> debbugs.gnu.org (full text, mbox):

From: Jim Meyering <jim <at> meyering.net>
To: jidanni <at> jidanni.org
Cc: 11809 <at> debbugs.gnu.org
Subject: Re: bug#11809: document "So how do we just simply make a backup file?"
Date: Fri, 29 Jun 2012 10:48:30 +0200
Jim Meyering wrote:
> jidanni <at> jidanni.org wrote:
>> (info "(coreutils) Backup options") should add some examples, for
>> "So how do we make a backup file of m?"
>> $ ls
>> m
>> $ cp -b m m #no go
>
> Thanks for the suggestion.
> I use this zsh/bash shell function:
>
> backup ()
> {
>   local i
>   for i in "$@"; do
>     command cp -bf "$i" "$i"
>   done
> }
>
> but as I inserted the above, I realize it's buggy.
> It doesn't propagate failure like you'd expect,
> so here's a better one:
>
> backup()
> {
>   local i fail=0
>   for i in "$@"; do
>     command cp -bf -- "$i" "$i" || fail=1
>   done
>   return $fail
> }
>
> That's already almost what info coreutils says:
>
>   Make a backup of each file that would otherwise be overwritten or removed.
>   As a special case, @command{cp} makes a backup of @var{source} when the force
>   and backup options are given and @var{source} and @var{dest} are the same
>   name for an existing, regular file.  One useful application of this
>   combination of options is this tiny Bourne shell script:
>
>   @example
>   #!/bin/sh
>   # Usage: backup FILE...
>   # Create a @sc{gnu}-style backup of each listed FILE.
>   for i; do
>     cp --backup --force -- "$i" "$i"
>   done
>   @end example
>
> I'll adjust that to reflect the above improvement:
> Do you think that's enough?

Here's the doc patch I suggested, but I'll hold off for now.
I'd like to hear if anyone thinks it's worth adding a new option,
which would obviate such a script.

From 3a1bc89c3e3ca277be49d4fceb60abb57e3fc9d2 Mon Sep 17 00:00:00 2001
From: Jim Meyering <meyering <at> redhat.com>
Date: Fri, 29 Jun 2012 10:45:31 +0200
Subject: [PATCH] doc: improve sample backup script

* doc/coreutils.texi (cp invocation): Make the backup script exit
with an accurate reflection of any failure.
---
 doc/coreutils.texi | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/doc/coreutils.texi b/doc/coreutils.texi
index 08ef2d8..5207c44 100644
--- a/doc/coreutils.texi
+++ b/doc/coreutils.texi
@@ -7675,9 +7675,11 @@ cp invocation
 #!/bin/sh
 # Usage: backup FILE...
 # Create a @sc{gnu}-style backup of each listed FILE.
+fail=0
 for i; do
-  cp --backup --force -- "$i" "$i"
+  cp --backup --force -- "$i" "$i" || fail=1
 done
+exit $fail
 @end example

 @item --copy-contents
--
1.7.11.1.59.gbc9e7dd




Information forwarded to bug-coreutils <at> gnu.org:
bug#11809; Package coreutils. (Fri, 29 Jun 2012 09:35:02 GMT) Full text and rfc822 format available.

Message #23 received at 11809 <at> debbugs.gnu.org (full text, mbox):

From: Bernhard Voelker <mail <at> bernhard-voelker.de>
To: Jim Meyering <jim <at> meyering.net>
Cc: 11809 <at> debbugs.gnu.org, jidanni <at> jidanni.org
Subject: Re: bug#11809: document "So how do we just simply make a backup file?"
Date: Fri, 29 Jun 2012 11:30:38 +0200
On 06/29/2012 10:48 AM, Jim Meyering wrote:
> Here's the doc patch I suggested, but I'll hold off for now.
> I'd like to hear if anyone thinks it's worth adding a new option,
> which would obviate such a script.

I think it's okay, that special backup case is described in the info
page of cp twice anyway.

> diff --git a/doc/coreutils.texi b/doc/coreutils.texi
> index 08ef2d8..5207c44 100644
> --- a/doc/coreutils.texi
> +++ b/doc/coreutils.texi
> @@ -7675,9 +7675,11 @@ cp invocation
>  #!/bin/sh
>  # Usage: backup FILE...
>  # Create a @sc{gnu}-style backup of each listed FILE.
> +fail=0
>  for i; do
> -  cp --backup --force -- "$i" "$i"
> +  cp --backup --force -- "$i" "$i" || fail=1
>  done
> +exit $fail
>  @end example
> 
>  @item --copy-contents

When we speak of "backup", then maybe "--preserve=all" would be nice.

BTW: that special backup case accepts -a which includes both -d and -R
which both are maybe not ideal if you speak about a backup of a regular
file. The former treats symlinks specially, and the latter is designed
to recurse into directories - both may be misleading (although -d may
make some sense in certain situation when creating a backup of a
symlink). WDYT?

Have a nice day,
Berny




Information forwarded to bug-coreutils <at> gnu.org:
bug#11809; Package coreutils. (Fri, 29 Jun 2012 10:27:01 GMT) Full text and rfc822 format available.

Message #26 received at 11809 <at> debbugs.gnu.org (full text, mbox):

From: Jim Meyering <jim <at> meyering.net>
To: Bernhard Voelker <mail <at> bernhard-voelker.de>
Cc: 11809 <at> debbugs.gnu.org, jidanni <at> jidanni.org
Subject: Re: bug#11809: document "So how do we just simply make a backup file?"
Date: Fri, 29 Jun 2012 12:22:01 +0200
Bernhard Voelker wrote:
> On 06/29/2012 10:48 AM, Jim Meyering wrote:
>> Here's the doc patch I suggested, but I'll hold off for now.
>> I'd like to hear if anyone thinks it's worth adding a new option,
>> which would obviate such a script.
>
> I think it's okay, that special backup case is described in the info
> page of cp twice anyway.
>
>> diff --git a/doc/coreutils.texi b/doc/coreutils.texi
>> index 08ef2d8..5207c44 100644
>> --- a/doc/coreutils.texi
>> +++ b/doc/coreutils.texi
>> @@ -7675,9 +7675,11 @@ cp invocation
>>  #!/bin/sh
>>  # Usage: backup FILE...
>>  # Create a @sc{gnu}-style backup of each listed FILE.
>> +fail=0
>>  for i; do
>> -  cp --backup --force -- "$i" "$i"
>> +  cp --backup --force -- "$i" "$i" || fail=1
>>  done
>> +exit $fail
>>  @end example
>>
>>  @item --copy-contents
>
> When we speak of "backup", then maybe "--preserve=all" would be nice.
>
> BTW: that special backup case accepts -a which includes both -d and -R
> which both are maybe not ideal if you speak about a backup of a regular
> file. The former treats symlinks specially, and the latter is designed
> to recurse into directories - both may be misleading (although -d may
> make some sense in certain situation when creating a backup of a
> symlink). WDYT?

Adding --preserve=all sounds like a good idea.
Thanks.

Allowing this little script to work also for non-regular files
seems like it'd be useful, too.  But it's beginning to look as if
this combination of options is both useful and involved enough that
the functionality should be provided by a new --only-backup option.




Information forwarded to bug-coreutils <at> gnu.org:
bug#11809; Package coreutils. (Sat, 30 Jun 2012 09:58:02 GMT) Full text and rfc822 format available.

Message #29 received at 11809 <at> debbugs.gnu.org (full text, mbox):

From: Jim Meyering <jim <at> meyering.net>
To: Bernhard Voelker <mail <at> bernhard-voelker.de>
Cc: 11809 <at> debbugs.gnu.org, jidanni <at> jidanni.org
Subject: Re: bug#11809: document "So how do we just simply make a backup file?"
Date: Sat, 30 Jun 2012 11:52:57 +0200
Jim Meyering wrote:
> Bernhard Voelker wrote:
>> On 06/29/2012 10:48 AM, Jim Meyering wrote:
>>> Here's the doc patch I suggested, but I'll hold off for now.
>>> I'd like to hear if anyone thinks it's worth adding a new option,
>>> which would obviate such a script.
>>
>> I think it's okay, that special backup case is described in the info
>> page of cp twice anyway.
>>
>>> diff --git a/doc/coreutils.texi b/doc/coreutils.texi
>>> index 08ef2d8..5207c44 100644
>>> --- a/doc/coreutils.texi
>>> +++ b/doc/coreutils.texi
>>> @@ -7675,9 +7675,11 @@ cp invocation
>>>  #!/bin/sh
>>>  # Usage: backup FILE...
>>>  # Create a @sc{gnu}-style backup of each listed FILE.
>>> +fail=0
>>>  for i; do
>>> -  cp --backup --force -- "$i" "$i"
>>> +  cp --backup --force -- "$i" "$i" || fail=1
>>>  done
>>> +exit $fail
>>>  @end example
>>>
>>>  @item --copy-contents
>>
>> When we speak of "backup", then maybe "--preserve=all" would be nice.
>>
>> BTW: that special backup case accepts -a which includes both -d and -R
>> which both are maybe not ideal if you speak about a backup of a regular
>> file. The former treats symlinks specially, and the latter is designed
>> to recurse into directories - both may be misleading (although -d may
>> make some sense in certain situation when creating a backup of a
>> symlink). WDYT?
>
> Adding --preserve=all sounds like a good idea.
> Thanks.
>
> Allowing this little script to work also for non-regular files
> seems like it'd be useful, too.  But it's beginning to look as if
> this combination of options is both useful and involved enough that
> the functionality should be provided by a new --only-backup option.

I went ahead and pushed this:

From 5f6c22fceedd0d350e1a8246d4d73840de666c7e Mon Sep 17 00:00:00 2001
From: Jim Meyering <meyering <at> redhat.com>
Date: Fri, 29 Jun 2012 10:45:31 +0200
Subject: [PATCH] doc: improve sample backup script

* doc/coreutils.texi (cp invocation): Make the backup script exit
with an accurate reflection of any failure.
Also, add --preserve=all.

Improved-by: Bernhard Voelker
---
 doc/coreutils.texi | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/doc/coreutils.texi b/doc/coreutils.texi
index 08ef2d8..954a1f8 100644
--- a/doc/coreutils.texi
+++ b/doc/coreutils.texi
@@ -7675,9 +7675,11 @@ cp invocation
 #!/bin/sh
 # Usage: backup FILE...
 # Create a @sc{gnu}-style backup of each listed FILE.
+fail=0
 for i; do
-  cp --backup --force -- "$i" "$i"
+  cp --backup --force --preserve=all -- "$i" "$i" || fail=1
 done
+exit $fail
 @end example

 @item --copy-contents
--
1.7.11.1.104.ge7b44f1




Added tag(s) fixed. Request was from Assaf Gordon <assafgordon <at> gmail.com> to control <at> debbugs.gnu.org. (Mon, 15 Oct 2018 17:18:01 GMT) Full text and rfc822 format available.

bug closed, send any further explanations to 11809 <at> debbugs.gnu.org and jidanni <at> jidanni.org Request was from Assaf Gordon <assafgordon <at> gmail.com> to control <at> debbugs.gnu.org. (Mon, 15 Oct 2018 17:18:01 GMT) Full text and rfc822 format available.

bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Tue, 13 Nov 2018 12:24:04 GMT) Full text and rfc822 format available.

This bug report was last modified 6 years and 279 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.