Backup Files

Hi,

Using the shell script, how can I backup the files.
/etc/password, /etc/group , /etc/shadow and more and needs a backup like /etc/password.12Mar12....

What UNIX are you using? - some of them have a sort of "automatic" backup feature.

Im using RHEL5 .. I need to manually backup some files... So listing those files, I need the extension of the file to be saved as .12Mar12

Here am not aware of your shell that you are using ..
Here's sample that am using on 1 of my server ...

 
#!/bin/bash
########################################
Targetpath=/usr/Backup
if [ ! -d $Target-path ]
then
    mkdir -p $Targetpath
fi
####################################### Files to be backuped
a="/etc/passwd, /etc/group, /etc/shadow"
#######################################
create=`date +%a-%d-%b-%Y-AT:%H:%M`
########################################
for ln in `echo $a`
do
   lnn=`echo $ln | sed  "s/,//g"`
    if [ ! -e $lnn ]
    then
          echo "$lnn file not EXIST"
    fi
    lst=` echo $lnn | awk -F"/" '{print $NF}'`
    tar -jcf $Targetpath/$lst-$create.bz2 $lnn
done
 

OP

 
[root@TESTLAB ~]# date
Sat Feb 11 11:54:02 IST 2012
[root@TESTLAB ~]# ls -lrt /usr/Backup/
total 12
-rw-r--r-- 1 root root 500 Feb 11 11:47 shadow-Sat-11-Feb-2012-AT:11:47.bz2
-rw-r--r-- 1 root root 938 Feb 11 11:47 passwd-Sat-11-Feb-2012-AT:11:47.bz2
-rw-r--r-- 1 root root 500 Feb 11 11:47 group-Sat-11-Feb-2012-AT:11:47.bz2
[root@TESTLAB ~]#


--Shirish Shukla

One idea. Assumes you meant ddMMMyy .

suffix=$(date +%d%b%y)
for filename in "/etc/password" "/etc/group" "/etc/shadow"
do
        # Remove echo when tested
        echo cp -p "${filename}" "${filename}.${suffix}"
done

Btw. Convention would be to use YYYYMMDD as a suffix because the directory order of the files would be chronological.