[ncolug] Re: Bash One Liner for Backup File

  • From: Jim Willeke <jim@xxxxxxxxxxx>
  • To: North Central Ohio Linux <ncolug@xxxxxxxxxxxxx>
  • Date: Fri, 12 Feb 2016 09:08:26 -0800

I agree, rsync is a better choice for these operations.
--times                 preserve modification times

Can do incremental or full backups.

Runs as a command or a client-to-damen process.

There are several similar scripts using rsync that will perform  (at least
nearly) any backup conditions you require.
https://blog.interlinked.org/tutorials/rsync_time_machine.html

https://github.com/samdoran/rsync-time-machine/blob/master/rsync-time-machine.sh






--
-jim
Jim Willeke

On Fri, Feb 12, 2016 at 7:14 AM, tech4u <techconsultant4u@xxxxxxxxx> wrote:

I know it is designed for doing more like directories/folders and keep
them up to date but I was saying it is an option and if you use the correct
flags(options) you can have the timestamp be what the file is.

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/11/16 3:07 PM, Chuck wrote:

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?



Other related posts: