Need a script to do daily backups


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Need a script to do daily backups
# 1  
Old 01-16-2005
Need a script to do daily backups

So I have a set of directories and files that I need to backup from /directory1/ to /directory2/ each night. I have some UNIX/SSH knowledge but don't assume I know a whole lot b/c I would hate to screw something up. Here's the knowledge I have:

I can access my server via SSH and can navigate to various folders and copy one file or directory at a time. And I can setup cron jobs. I have no knowledge of creating scripts or anything really of that sort.
# 2  
Old 01-16-2005
Do

See the man pages of cp comand.

cp -R sourceDir DestinationDir


Try this as command .. and tailor it as per yr needs.


Put it as crontab after that.
# 3  
Old 01-16-2005
I know how to copy files (I mentioned that in my post) and setup cron jobs (I mentioned that too). I need help past that.
# 4  
Old 01-16-2005
a script is nothing but set of unix commnads.

Put all your unix commands in one file and run that script.

For example, you are copying sourceDir to a desination ..
your commands would be some thing like this .. say

cp -R /source/Dir1 /destination/Dir2
cd /destination
mv Dir2 Dir1

Run these command onafter another. This is what you wanted to do.


If you achieved what you wanted ...
Next ... put all these commands in a script let's say that sample.sh


your sample.sh contains
cp -R /source/Dir1 /destination/Dir2
cd /destination
mv Dir2 Dir1

Then try to run sample.sh as a command.
Add +x permission to run the command as follows

chmod +x samle.sh

run the sample.sh from the directory where sample.sh resides.


If it gives any prblems with PATH ... run like this ...

./sample.sh


since you know how to include it in crontab ...
add this sample.sh in crontab to schedule it to run at a certain time daily.

Hope this helps !!!

Last edited by bhargav; 01-18-2005 at 08:59 PM..
# 5  
Old 01-16-2005
Dear bhargav,

Please visit this thread in the Moderators area:

https://www.unix.com/moderator-s-forum/16342-bhargav-please-edit-your-posts.html

Thanks,

Neo
# 6  
Old 01-18-2005
Okay...I just can't get this to work. Any chance somebody could contact me via AIM or MSN and walk me through this?

Last edited by RTM; 01-18-2005 at 08:37 PM..
# 7  
Old 01-18-2005
JPigford - check the Rules - I removed your info for instant messages.

It's simple - to do a script you have a choice of shells or languages - choose one that you are use to using (such as the shell you use normally - do a
echo $SHELL to find out what you are using).

Once you have that, cd to your home directory - vi a new file (such as my-new-script)
$ cd
$ vi my-new-script
Insert the commands in the same order you would run them normally from the command line - only difference - add #!/bin/sh or whatever shell you are using at the top - this lets the system know what you are running these commands under

#!/bin/sh
/bin/cp /dirA/* /dirB/*
exit

Then use chmod as suggested to change the script to executable
A script is putting all the commands you usually have to do into a file to run - it's doing what you would do automatically (via cron if needed). The only thing a script does it make it so you don't have to type those commands every time.

Try this on your system:
$ cd
$ vi hbo
i
#!/bin/sh
date +'%n %D %A %T%n'
exit

Hit the escape key, put in a wq to write-quit from the vi editor
$ chmod 744 hbo
$ ./hbo

01/18/05 Tuesday 19:44:04

$

That's all there is to it -
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Run script no more than twice daily WITHOUT cron

Can I run a script no more than twice a day without using cron? Maybe create a file when script is first run and check its date? (7 Replies)
Discussion started by: drew77
7 Replies

2. UNIX for Beginners Questions & Answers

/etc/cron.daily script is not being executed

Hi All I have created a file in /etc/cron.daily on redhat linux 7.3 version host called applicationscript cat applictaionscript #!/bin/bash /prod/data/routine.sh cat /prod/data/routine.sh #!/bin/bash #details regular=/prod/data/jboss/logs backup=/prod/data/logs #echo "Moving logs"... (3 Replies)
Discussion started by: anil529
3 Replies

3. Shell Programming and Scripting

Help me with daily monitoring script

find /usr/IBM/FileNet/BulkUploaderScript/$i/Log/SuccessLog \( -newer range_start -a \! -newer range_end \) -exec wc -l {} \; |awk '{total+=$1-1} END {print total}' >>$LOGFILE I need to print time stamp of the files int the paticular period .Please modify the above script so that i get... (34 Replies)
Discussion started by: RaghavendraT
34 Replies

4. Shell Programming and Scripting

Script for daily use

I have a clear case command for example. ct lsprivate -co this displays the list of checked out files. and i have many views where i work daily I need a script which can run daily at our specified time. setting each and every view i have and list the check outs i have in them. and consolidate... (10 Replies)
Discussion started by: Syed Imran
10 Replies

5. Shell Programming and Scripting

Daily health check script

Hi I am still learning how to write shell scripts, so I started to write a script like this: #!/bin/sh date echo outputOK () { echo $1 "" } outputOK () { echo $1 "" } for vol in `/usr/bin/grep -E 'hfs|vxfs|nfs|cifs' /etc/fstab | egrep -v '^#' | awk '{ print $3 }'` do if... (7 Replies)
Discussion started by: fretagi
7 Replies

6. Shell Programming and Scripting

Help with Daily DB growth script

Hello, I have a script SELECT TO_CHAR(creation_time, 'RRRR Month') "Month", SUM(bytes)/1024/1024 "Growth in MB" FROM sys.v_$datafile WHERE creation_time > SYSDATE-365 GROUP BY TO_CHAR(creation_time, 'RRRR Month') / It produces output similar to this Month ... (2 Replies)
Discussion started by: jnrpeardba
2 Replies

7. UNIX for Dummies Questions & Answers

Run a .sh script daily

Hi, I juat wondering how can you set it up so that .sh files will execute automatically once a day. from google I've got use crontab but when I type this into my session it say I am not allowed to use this programme. Any other ways to achieve what I'm looking for? thanks (1 Reply)
Discussion started by: blackieconnors
1 Replies

8. Shell Programming and Scripting

Perl script to invoke Cold Backups

Hello, I am relatively new to Perl and I need help in creating a Perl script to automate a crontab job that starts and shutdowns multiple servers one server at a time. Script is to be run once a week. Below are the steps needed for the job... 1. Start stopping server1 and server2 using... (3 Replies)
Discussion started by: northern1969
3 Replies

9. Shell Programming and Scripting

Script to delete logs or take backups under specific user

I have to write a shell script like this-- 1) Utility will be run under the directory owner. 2) This utility will clean files in ABC/logs. And following logs will be backed up or deleted. Dispatcher Logs Middle tier Logs Sage log Sage monitor log Sage db clean up result log Core files ... (12 Replies)
Discussion started by: namishtiwari
12 Replies

10. UNIX for Dummies Questions & Answers

backing up file everytime script run and saving other backups

how would i go about creatng a backup of a file everytime a script is run so that the next time it is run the old backup gets pushed back and the most recent backup is 1st. (new)backup.1 (old)backup.2 that kind of idea?? (4 Replies)
Discussion started by: knc9233
4 Replies
Login or Register to Ask a Question