Linux - SoftwareThis forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I am not familiar with script writing , I would like to have a simple bash script to do the backup , the logic is simple.
1) use tar to backup a all files in directory to a specific path , the command should as below , the date is the current date
tar -zcvf /backup_path/backup.date /ora_database/*
2) only keep the backup file for 3 days , remove the files ( backup.date ) which is elder than 3 days .
3) send the alert mail to administrator to notify it is success or failure .
You could use a script, roughly like this. Lines beginning with # are comments accepted by bash. I've used zero as a return code indicating success from the tar command. However, you will need to determine whether or not you can allow/expect minor errors that might produce a non-zero return code, and still consider it successful. So in your case, it might be some value other than zero. Also, I was hoping it is acceptable in your situation, to remove old backup files in the same script, before the script makes the new backups. Hopefully I've included enough comments in the script to explain what it's doing, and with this as a guide, just a quick glance at the man page for bash will solidify the fine points of the very limited subset of bash syntax I've used here.
Code:
#!/bin/bash
# The first line expects that your bash executable is located in bin.
# If it's someplace else, put the proper path in the line.
cd /backup_path/
# Remove any backup files older than 3 days.
find . -mtime +3 -exec rm {} \;
# Assign to variable named current_date the current date, formatted for use in a file name.
current_date=`date +%Y_%m_%d`
# Do the backup using today's date in the file name.
tar -zcvf ${current_date}.tar.gz /ora_database/*
# Set the value of variable named backup_status from return code $? of tar command.
if [ $? -eq 0 ]
then
backup_status='Success'
else
backup_status='Failure'
fi
# Send mail with backup status to admin.
mailx -s "${current_date} backup status" root<<<${backup_status}
I am not familiar with script writing , I would like to have a simple bash script to do the backup , the logic is simple.
1) use tar to backup a all files in directory to a specific path , the command should as below , the date is the current date
tar -zcvf /backup_path/backup.date /ora_database/*
2) only keep the backup file for 3 days , remove the files ( backup.date ) which is elder than 3 days .
3) send the alert mail to administrator to notify it is success or failure .
You've been here since 2003, and have posted MANY requests for others to write scripts for you..just a few examples:
If you need scripts, I would suggest you learn to write them yourself. You've been pointed to scripting tutorials before, but keep coming back asking for others to write scripts for you. I'll again give you one of the MANY, easy to find scripting tutorial links: http://tldp.org/LDP/abs/html/
There is no one who won't gladly help you, but after nine years, you should be showing some effort of your own, rather than just asking people to do your scripting for you.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.