Assistance in Shell script on placing files across mount points.
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
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.
Assistance in Shell script on placing files across mount points.
Hi Experts,
Need assistance from you. Given below is my current requirement. Currently help me on the same.
I have a database with x number of files (192 at the moment, but will vary from time to time). I am going to copy these files to another location on the same server thorugh shell script. Problem with total size of 192 files is approx 900 GB (again this will vary from time to time).
My shell script should calculate the free space available at present in the server on each of the mount point (can be filled till it reaches 95%). Always 5% free space should be available free for future growth.
After calculating, it should prepare another flat file with following details
FileName1 - /ora01 - 30 GB
FileName2 - /ora01 - 70 GB
(lets assume it can put only 100GB worth data in /ora01 and so it should switch to next available mount)
FileName3 - /ora05 - 30 GB
and so on....
Could you please help me with the same? Please let me know if anyone needs further clarification on the above requirement.
Hi,
Yes. These are oracle databfiles and database is in archive log. So should be fine.
Now let me tell how we do this process at present manually so that it will easy for everyone to understand the requirement.
a) First we pull the data file names and current sizes from source database in a spread sheet
b) We execute df command on server and calculate free space available in each of the mount points
c) We try to split the files and place it across 'n' number of mount points depending upon file size and free space available.
d) once we decided we create a flat file with above information (file-name & mount point to which it needs to be copied).
e) This flat file will be input for the process which does the copy job.
Now we are trying to automate the process of flat file creation (from step b to d through shell script and step a will be input for this process.
Please let me know if still the requirement is unclear.
That would work if you wanted to paste multiple file parts together, I don't believe that is what the OP is after.
It looks like the OP wants to make a copy of the original DB (either as a cold backup, or as a duplicate of the DB)
Hi, manickaraja,
As the DB is in Archive Log mode, it would make more sense (to me) to take a hot backup (why else would you use Archive Log mode?) this removes the need to shutdown the DB in order to back it up.
Once you have a hot backup, you can duplicate the DB. You can use the parameter file of the Duplicate DB to transform your datafile filenames from the production locations to the new duplicate locations.
Hi,
We are doing a cloning and it is from a active data guard. We dont want to use RMAN Duplicate database for various reasons and hence we are using RMAN Image copy for copying datafiles after which we will be restoring the database by applying archive logs from data guard standby database.
Now if any of you have any ready made code or can easily give me one to fit the datafiles into various mount points depending upon space available on each of them, it will be of great help.
In theory, you can run out of free space in all mount points.
The things the script must do are:
(1) Create a list (or array) of mounted file systems.
(2) For each file,
(2a) For each mounted file system, compare the size with the available area or try the next file system.
Hi,
The actual problem I am facing is I cannot copy the file , check free space after copy and proceed with another file copt to same file system depending upon space available.
I have to write a script first for performing file copies and then execute it. So for writing the script I need to decide which all files will fit in which mount point. So somehow I have calculate within the program before availing the space. How can I do it?
while
<check if fs still has space, store the size to a variable for later use>
do
<with the value of the variable, look for the file that best fits the remaining space then copy it>
done
#!/usr/bin/perl
###
### Read datafiles into hash containing the datafile and it's size in KB
###
open(DATAFILES, "datafiles") or die "Could not open datafiles\n";
while(<DATAFILES>) {
chomp; # remove charage return
($v_file, $v_size)=split(/ /, $_);
$datafiles{"$v_file"}="$v_size";
}
close(DATAFILES);
###
### Read mountpoints into hash containing mountpoint and available
### space - 5%
###
open(MOUNTPOINTS, "mountpoints") or die "Could not open mountpoints\n";
while(<MOUNTPOINTS>) {
chomp;
($v_mount, $v_size, $v_avail)=split(/ /, $_);
$max_avail=int($v_avail - ($v_size / 20));
$mountpoints{"$v_mount"}="$max_avail";
}
close(MOUNTPOINTS);
At this stage, you have read the information into the script and stored the bits you need to work with.
Left to do
==========
List the datafiles in size order (largest first)
List the mountpoints in size order (smallest first)
Find which mountpoints the datafiles fit in
`-- Store the information about which datafile to allocate to which mountpoint
`-- reduce the max_avail of the relevant mountpoint
`-- repeat until either all datafiles are allocated or you run out of space
`-- create a log of errors & warnings
That's all I have the time for at the moment, if you progress the script before I do, please post the code.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.