Thinking Out Loud

May 2, 2015

Backup file using copy with date append

Filed under: linux — mdinh @ 3:51 am

How many ways are there to backup a file? Copy and append .bak, .sav, .orig, etc …

I was looking for a simple, consistent, yet elegant way to do this.

Good thing for Google (disclaimer I do own the stock), I came across this blog – http://blog.justin.kelly.org.au/how-to-copy-file-and-append-current-date-in-l/

Demo:

oracle@arrow:hawklas:/home/oracle
$ ps
  PID TTY          TIME CMD
 4343 pts/1    00:00:00 bash
 6915 pts/1    00:00:00 ps

oracle@arrow:hawklas:/home/oracle
$ ls -l logdump*
-rw-r--r--. 1 oracle oinstall 2487 Apr 19 11:09 logdump.hst

oracle@arrow:hawklas:/home/oracle
$ filename=logdump.hst

oracle@arrow:hawklas:/home/oracle
$ cp $filename{,.`date +%d%b%Y-%H%M`}

oracle@arrow:hawklas:/home/oracle
$ ls -l logdump*
-rw-r--r--. 1 oracle oinstall 2487 Apr 19 11:09 logdump.hst
-rw-r--r--. 1 oracle oinstall 2487 May  1 20:31 logdump.hst.01May2015-2031
Advertisements

Leave a Comment »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Blog at WordPress.com.

%d bloggers like this: