Computing.Net > Forums > Unix > backup a file with SHELL SCRIPT

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

backup a file with SHELL SCRIPT

Reply to Message Icon

Name: Justin
Date: January 23, 2003 at 12:51:21 Pacific
OS: Solaris 8
CPU/Ram: SPARC
Comment:

Hi,
I was wondering if anybody knew how to make a shell script that will make a backup of a file example (mv out out.bak) but the next time you run the script i want the original backup file to still be there.


#!/bin/bash
# Copy mc2.xml to cmd.cmd and run perl script for out file

echo
echo "Your current directory is: "
pwd
echo
echo "Backing up old output file..."
cp out out.bak
rm -rf out
cp ~/xml/mc2.xml ~/xml/html/cmd.cmd
echo "Copying MC2 and parsing output..."
perl index.cgi cmd.cmd > out
echo "Finished making file 'out'"

-----------

I would like to be able to keep the original backup file out.bak and next time I run the script move the newer out file to out.bak1 or somthing along those lines.



Sponsored Link
Ads by Google

Response Number 1
Name: Jerry Lemieux
Date: January 23, 2003 at 17:39:34 Pacific
Reply:

Why not simply:

mv out out.bak.`date "+%y%m%d"`

Better then out.bak.1, out.bak.2, etc....

If you are doing this multiple times in the same day, add a time stamp to the date.


0
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Unix Forum Home


Sponsored links

Ads by Google


Results for: backup a file with SHELL SCRIPT

Create a file with a path? www.computing.net/answers/unix/create-a-file-with-a-path/4820.html

Process files using shell script www.computing.net/answers/unix/process-files-using-shell-script/3669.html

shell script for comparing file www.computing.net/answers/unix/shell-script-for-comparing-file-/7685.html