[ncolug] Re: Bash One Liner for Backup File

  • From: Chuck <cstickelman@xxxxxxxxxx>
  • To: ncolug@xxxxxxxxxxxxx
  • Date: Thu, 11 Feb 2016 15:07:48 -0500

On Thu, 2016-02-11 at 08:47 -0500, tech4u wrote:

Why not use rsync as a one time command and run it manually if you
wish?

Cory
-- 
Technology is dominated by two types of people: those who understand
what they do not manage, and those who manage what they do not
understand. -- Putt's Law

The only way to discover the limits of the possible is to go beyond
them into the impossible. -- Arthur C. Clarke 
On 2/10/16 6:06 PM, Chuck wrote:
On Wed, 2016-02-10 at 07:43 -0500, Mike wrote:
On 02/10/2016 12:38 AM, Rob Gibson wrote:
Chuck,

There is a one-liner that I have seen you use to make a copy of
a file
you are modifying with a datestamp appended to the filename,
and I have
been trying to rack my brain for that one-liner.

If I recall, it used 'cp' with a single argument?

Thanks,
Rob

Not Chuck, but this should work...

cp devmem2.c devmem2.c-$(date +'%Y-%m-%d')

Mike

To unsubscribe send to ncolug-request@xxxxxxxxxxxxx with
'unsubscribe' in the Subject field.

That's very close to what I used to use:
cp -p somefile{,.$(date +%Y%m%d.%H%M%S}

to copy somefile.txt to somefile.txt.CCYYMMDD.hhmmss

I didn't like the way that handled the extension, so at work I
built a shell function that can accept a list of files followed by
a directory and it will insert the .CCYYMMDD.hhmmss. part in front
of the last extension for each and place the copy in the named
folder, stripping off directories.  I named the function cpdate-8.6 
and if I call it like:

cpdate-8.6 * ./Archives/

it will make a copy of each file in the current directory, all with
the same time-stamp, and store them in the Archives directory.
 Works nice.  It uses cp -pPUI I think. The function became much
larger than I anticipated once I started accepting any random path.
I finally cheated and used a library from the Internets to convert
all file names to fully-qualified file names and then I had to have
some logic for proper handling of file anme extensions, in case the
file didn't have one, or had multiple.

It's a nice exercise. I may try it on this laptop now without the
library...





I use Rsync for many things, but I've never used it to make backup
copies of a file (usually prior to editing it) on the same system.  I'd
still ahve to code up something to add a unique timestamp extension
though, wouldn't I?

Attachment: signature.asc
Description: This is a digitally signed message part

Other related posts: