LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This 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


Reply
  Search this Thread
Old 08-21-2012, 01:56 AM   #1
ust
Senior Member
 
Registered: Mar 2003
Location: fasdf
Distribution: Debian / Suse /RHEL
Posts: 1,130

Rep: Reputation: 31
Backup script


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 .


It is very pleasure if can help .

Thanks.
 
Old 08-21-2012, 04:38 AM   #2
rigor
Member
 
Registered: Sep 2003
Location: 19th moon ................. ................Planet Covid ................Another Galaxy;............. ................Not Yours
Posts: 705

Rep: Reputation: Disabled
Hi ust!

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}
HTH.
 
Old 08-21-2012, 01:27 PM   #3
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,634

Rep: Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965
Quote:
Originally Posted by ust View Post
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:

https://www.linuxquestions.org/quest...er-4175413626/
https://www.linuxquestions.org/quest...te-4175413358/
https://www.linuxquestions.org/quest...column-944377/
https://www.linuxquestions.org/quest...script-946113/

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.

Last edited by TB0ne; 08-21-2012 at 04:15 PM.
 
Old 08-21-2012, 06:28 PM   #4
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,359

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
What TB0ne said ++
 
1 members found this post helpful.
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
What happens with backup-manager.org (very useful backup script)? Murz Linux - Software 3 07-27-2010 06:46 AM
Newbie trying to write a simple backup script to backup a single folder Nd for school stryker759a Linux - Newbie 2 09-16-2009 08:52 AM
Need help with script to organise files into folders as part of DVD backup script jasybee2000 Linux - Newbie 5 06-15-2009 07:29 PM
BAckup Script? your_shadow03 Linux - Newbie 1 02-11-2009 08:40 PM
how to create backup MYSQL Script to backup my database for every 1hour RMLinux Linux - Newbie 3 11-20-2008 10:13 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 10:52 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration