Monday, January 30, 2012

Quickly Make a Backup of a File in Linux

So you are Admin-ing away, and you are following SOP and making backups of all the files you edit.  Right?  However, as you have 100 servers to do and 5 files on each, that is a lot of typing!  You become lazy and forget the backup on one file, and then it happens.  A reboot hangs and you have no idea why, except that you were just editing system files...

Here is a quick way to backup any file:
cp /path/to/file{,.bak}

Example:
cp /etc/fstab{,.bak.2012-01-30}

The above example will produce a file named: /etc/fstab.bak.2012-01-30

This may seem a trivial savings in typing, but when you are scripting or in a hurry it can be a great time saver.  It also protects the backup file name from any typos. 

Make those backups and save yourself the frustration of having to go into single user to fix it!  Better procedures equal less downtime.

No comments:

Post a Comment