Friday, February 03, 2006

Taking Backups

I am Trying my hand on shell script.

What I wanted was I need to mention the name of file or directory
and it should take the back of that with Year, day, month, time etc...

Heres the script,

#!/bin/bash
echo Give the File or Directory Name for which Want you to take Backup :
read filename
if [ "$(tar czvf $filename.$(date +%Y%m%d-%H%M%S).tgz $filename)" ]; then
echo The Backup is taken
else
echo There is no Such File.
fi

and saved it as --- archive.sh

[root@mainproxy Unix_Shell]# ls
archive.sh doc

[root@mainproxy Unix_Shell]# ./archive.sh
Give the File or Directory Name for which Want you to take Backup :
doc
The Backup is taken

[root@mainproxy Unix_Shell]# ls
archive.sh doc doc.20060203-063542.tgz

Bash Programming can be found here and here.

No comments: