Operating System - HP-UX
1745875 Members
4437 Online
108723 Solutions
New Discussion юеВ

Re: Script needed for backup with prompt of date used in file naming conventions

 

Script needed for backup with prompt of date used in file naming conventions

We have a script that tars a group of files. Sometimes it fails because people forget to put tapes, unprotect the tapes, etc.

I am going on vacation and basically i want to create a script where the command

tar -cvf dev/rmt/0m /backup/*[Date name}.Z

Basically I want them to execute the script then the date of the specific backup will be prompted for input.

Here's an example the backup for 10/12/2005.
The files are backed up to /backup/daily and the 3 files are needed to backed up.
jBeforeCob-20101012.Z. jAfterCob-20101012.Z and jReReporter-20101012.Z.

So the 3 files all need to backed up to tape. I just want the user to input the date.

Do these user need root access for this?

Any help would be appreciated, I am going on vacation and I am the only Unix Admin, so I am trying to make easy for non Unix familiar people.
4 REPLIES 4
Steven Schweda
Honored Contributor

Re: Script needed for backup with prompt of date used in file naming conventions

> [...] i want to create a script [...]

What's stopping you?

> Do these user need root access for this?

My psychic powers are too weak to tell me
anything about the owner/group or permissions
of these files (or of the tape device).

Why ask? Why not simply try it? Reality is
often more reliable and trustworthy than free
advice on a forum like this one. Especially
when no non-psychic here has the information
needed to justify an opinion.

> [...] then the date of the specific backup
> will be prompted for input.

If the date is always (or usually) today's
date, then you might offer that as a default
value.

> [...] people forget to put tapes, unprotect
> the tapes, etc.

Can a script load the tape drive with a
properly configured tape?
TwoProc
Honored Contributor

Re: Script needed for backup with prompt of date used in file naming conventions

Chris,

to get a string from a user on the screen from a running script, the command is "read."

for example, inside a script...

read answer

will wait for the user to input a string, and it will be stored in $answer.

if you run the command

echo $answer

the string in your case the date string would be shown on screen.

a rough example of what you may be looking for:

echo "Enter Date:"
read backupdate

tar -cvf dev/rmt/0m /backup/*${backupdate}.Z



Hope this helps.
We are the people our parents warned us about --Jimmy Buffett

Re: Script needed for backup with prompt of date used in file naming conventions

TwoProc this is it. I couldnt remember the exact syntax.

Thanks for the help
James R. Ferguson
Acclaimed Contributor

Re: Script needed for backup with prompt of date used in file naming conventions

Hi Chris:

Instead of interactively reading from user input, consider passing the requisite data as an argument to your script. This allows you to 'cron' the script too. In a simple form, you could do:

# cat ./mybackup
#!/usr/bin/sh
[ -z "$1" ] && { echo "Usage $0: backup_date"; exit 1; } || BUDATE=$1
echo "backing up for ${BUDATE}"
#

Regards!

...JRF...