- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Script to back up filesystem after it reaches 20 %...
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-27-2004 05:37 PM
04-27-2004 05:37 PM
Script to back up filesystem after it reaches 20 %....
After the backup process is complete, the script should delete files from the filesystem. This script should run as an continous process and should monitor the filesystem for its pre-defined level. This is basically required for my SAP R/3 environment where I need to backup my redo logs on a tape library. Also advice if there is an better process than this.
Regards
-Charu
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-27-2004 05:50 PM
04-27-2004 05:50 PM
Re: Script to back up filesystem after it reaches 20 %....
if [ $# -lt 2 ]
then
echo "Usage $0 fs trigger"
exit 0
fi
FS=$1
TR=$2
USAGE=`df -k $FS |awk '{print $4}' |sed "s/%//g"`
if [ $USAGE -gt $TR ]
then
tar cvf /dev/rmt/0m $fs
if [ $? -ne 0 ]
then
echo "Hey bakcup failed |mail -s URGENT sysadmin@company.com"
exit8
else
rm $FS/*
fi
else
echo "USAGE of $FS is currently $USAGE"
fi
Schedule it in cron for every 30 minutes ?.
Regds,
Kapil
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-27-2004 06:01 PM
04-27-2004 06:01 PM
Re: Script to back up filesystem after it reaches 20 %....
Thanks for the script.
Can you educate me as to where should I enter the name of the filesystem and the percentage which I need to pre-define.
As I am new to unix, please try to elaborate as much as you can.
Thanks in advance
Regards
-Charu
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-27-2004 06:14 PM
04-27-2004 06:14 PM
Re: Script to back up filesystem after it reaches 20 %....
Thanks for the script.
Can you educate me as to where should I enter the name of the filesystem and the percentage which I need to pre-define.
As I am new to unix, please try to elaborate as much as you can.
Thanks in advance
Regards
-Charu
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-27-2004 07:06 PM
04-27-2004 07:06 PM
Re: Script to back up filesystem after it reaches 20 %....
./script /database/arch 20
Syntax :
script
Do a proper testing before put anything to production ! Comment oput the tar and rm entries and have some friendly mesgs so that you are sure what u r doing !
Regds,
Kaps
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-27-2004 07:09 PM
04-27-2004 07:09 PM
Re: Script to back up filesystem after it reaches 20 %....
I would be glad to interpret Kapils shell script.Let us assume you create the shell script with the name "fscheck".
-----------------------------------------------
if [ $# -lt 2 ]
then
echo "Usage $0 fs trigger"
exit 0
fi
-----------------------------------------------
These line actually test the correct number of parameter/argument you are likely to pass when you are executing shell script.Here it is expecting two argument.first argument indicates the path to your filesystem under scrutiny,Sencond argument is indicative of the percentage when you want to trigger the backup.ex: "fscheck /var 20" would mean that you are checking /var filesystem for 20% accupancy.
---------------------------------------------
USAGE=`df -k $FS |awk '{print $4}' |sed "s/%//g"`
---------------------------------------------
Here Kapil is calculating the current usage and assigning the value to variable USAGE.
---------------------------------------------
if [ $USAGE -gt $TR ]
then
tar cvf /dev/rmt/0m $fs
if [ $? -ne 0 ]
then
echo "Hey bakcup failed |mail -s URGENT sysadmin@company.com"
exit8
else
rm $FS/*
fi
else
echo "USAGE of $FS is currently $USAGE"
fi
---------------------------------------------
here kapil has used nested IF conditions.basically the first if loop tests wether the usage is greater than the value you mentioned as the second argument($TR).If the test failed it simply echos the current usage of the fs.If the test succeded it starts backing up the filesystem using tar command.after the execution of tar The script tests wether tar command succeded or not using another "if" condition with the help of the variable "$?".if the test failed it removes the backedup files(that is if tar command succeded).
NOTE: here i would suggest to use rm -rf $FS/* instead of rm $FS/* considering the fact that a directory might be encontered.
if the test succeded(if tar command fails), the script sents you a mail with URGENT as message title.
NOTE:please use "exit" in the script instead of "exit8" i guess it would have been a typo.
regards
Senthil
p.s:
points
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-27-2004 07:28 PM
04-27-2004 07:28 PM
Re: Script to back up filesystem after it reaches 20 %....
I did miss a space after exit in that statement. You have explained it the way i thought. Normaly redologs are just files and there is rare chances of hving a directory in there.
Infact I wanted the requester to write his own script with his own knowledge rather than trying something which he doesn't know !.
I can suggest few more options like compress the logs file and move it to a directory which will be backed up daily and somebody can query the backup whether it is successful and then delete the files. Something like take a list of files in this directory in to a loop, check in "tar tvf" to see whether it is backed up if "YES" then delete it from filesystem
Anyway it kis upto him to think and implement the best
Kaps
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-27-2004 07:37 PM
04-27-2004 07:37 PM
Re: Script to back up filesystem after it reaches 20 %....
but comparing to Oracle redo logs I assume
its continuously I/O'ed log.In that case how
could you delete files from filesystem?
And afaik (Oracle again) isn't it being rewriten after a space limit is reached?
I assume in those real time I/O's you can better think about some sort of snapshot solution (filesystem or storage level).
rgds,
Zeev
P.S pls give points to the crowd.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-27-2004 07:44 PM
04-27-2004 07:44 PM
Re: Script to back up filesystem after it reaches 20 %....
This script is not working. I tried running it but it displays errors right from line no 14 and then line no 19, 21...
Request you to guide me with a script and the entire steps to run it.
Please be sweet and simple.
-Charu
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-27-2004 07:55 PM
04-27-2004 07:55 PM
Re: Script to back up filesystem after it reaches 20 %....
run the script as follows and if possible post the o/p in the forum
sh -x ./script fs_name 20
Also comment out those rm and tar commands ..
Kaps
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-27-2004 10:10 PM
04-27-2004 10:10 PM
Re: Script to back up filesystem after it reaches 20 %....
+ [ 2 -lt 2 ]
+ FS=/opt
+ TR=20
+ + df -k /opt
+ awk {print $4}
+ sed s/%//g
USAGE=:
Kb
Kb
used
./charu[9]: Syntax error at line 20 : `fi' is not expected.
# df -k /opt
/opt (/dev/vg00/lvol6 ) : 1513328 total allocated Kb
280752 free allocated Kb
1232576 used allocated Kb
81 % allocation used
#
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-27-2004 10:15 PM
04-27-2004 10:15 PM
Re: Script to back up filesystem after it reaches 20 %....
Kaps
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-27-2004 10:18 PM
04-27-2004 10:18 PM
Re: Script to back up filesystem after it reaches 20 %....
Looking at ur error:
Syntax error at line 20 : `fi' is not expected.
it seems there is some mismatch with the if branching. It is written as follows:
1. if [expr]
then commands;
fi
2. if [expr]
then commands;
else commands;
fi
Make sure that "if" is ended with correspoding "fi". If you use "if" inside "if" then it has to ended first with "fi" then the parent one again with "fi"
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-27-2004 10:23 PM
04-27-2004 10:23 PM
Re: Script to back up filesystem after it reaches 20 %....
In your script replace
USAGE=`df -k $FS |awk '{print $4}' |sed "s/%//g"`
with
USAGE=`df -k /var|tail -1|tr -s " "|cut -d " " -f 2`
Please NOTE:this is a command substitution and hence back quote to be used AND thus,not single quotes.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-27-2004 10:25 PM
04-27-2004 10:25 PM
Re: Script to back up filesystem after it reaches 20 %....
can you attach the script you have written.I will run it in my system and return you the corrected version.
regards
Senthil
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-27-2004 10:58 PM
04-27-2004 10:58 PM
Re: Script to back up filesystem after it reaches 20 %....
spare the expense of sending your shell script.I have tried the shell script which kapil has indicated(ofcourse with major modification to removing the files...etc...).
I can assure you it will work fine 100% on hpux systems if you replace
USAGE=`df -k $FS |awk '{print $4}' |sed "s/%//g"` with
USAGE=`df -k /var|tail -1|tr -s " "|cut -d " " -f 2`
regards,
Senthil