Sponsored Content
Top Forums UNIX for Dummies Questions & Answers Backup Rationalisation Script - Help Required Post 302557373 by jeked on Wednesday 21st of September 2011 04:14:36 AM
Old 09-21-2011
Updated code

Ok so i have made some progress but again im stumped... this is what i have so far:

Code:
#!/bin/sh
#Version 3.1
#Program to rationalise the off site backup in comparison to the current client file system.

processFolder() {
        if !(test -d "$1") then
                echo "do stuff with file"
                # Use cases for file checking:
                #       a) SRC has a file DEST doesn't < Warning report
                #       b) DEST has a file SRC doesn't < Mark for deletion
                #       c) SRC has a bigger size file to DEST < Warning report
                #       d) DEST has a bigger file size to SRC < Warning report
                #*      e) SRC has a diff date file to DEST < Warning report
                #       f) DEST has a directory SRC doesn't < Mark for deletion

                # Pesudo Code for file checking:
                #       if exits on SRC = yes then
                #               if same size = yes then
                #                       process_folder
                #               if same size = no then #c), d)
                #                       flag warning
                #       if exist on SRC = no then #b)
                #               mark for deletion
                #
                #elif item = directory then
                #       if exists on SRC = yes then
                #               process_folder
                #       if exists on SRC = no then #f)
                #               mark for deletion
                #
                #else
                #       echo "'current item' Is not file or directory"               


 
                # Existence checking
                # Need help here:
                # Does file exist on client server?

                # Size Checking               
                # BAKS contains size of file1
                # CLNTS contains size of file2
                BAKS=$(stat -c%s "$1")
                CLNTS=$(stat -c%s "$2")
                if [[ "$BAKS" -lt "$CLNTS" ]]; then
                          echo "Bbackup file is smaller"
                          echo "Warning, backup not successful"
                elif [[ "$BAKS" -gt "$CLNTS" ]]; then
                         echo "Client file size is smaller"
                         echo "Warning, backup not successful"
                elif [[ "$BAKS" -eq "$CLNTS" ]]; then
                         processFolder ()
                fi
               
        else
                cd $1
                for i in *
                do
                        processFolder "$i"
                done
        fi
}

parseArgs()
{
                if [  $# -lt 4 -o $# -gt 5 ]; then
                        printHelp
                        return 1;
                else

                        while [ $# -gt 0 ]
                        do
                                case "$1" in
                                        -d)   D_ARG=1;;
                                        -c)   CF_ARG=1; CF_VAL=$2; shift;;
                                        -b)   BF_ARG=1; BF_VAL=$2; shift;;
                                        ?) printHelp;;
                                        *) echo "$1 not an option"; printHelp;;
                                esac
                                shift
                        done
                fi
}

printHelp()
{
        echo "Usage: $0 -d -c [filename] -b [folder location]"
        echo ""
        echo "-d = Dry-run."
        echo "          ie. Run through the program as normal but only output a file with the changes that could be made."
        echo ""
        echo "-c = Client File input."
        echo "          ie. Supply the location and name of the previously generated client file list."
        echo ""
        echo "-b = Backup Folder Location."
        echo "          ie. Supply the location of where the backup is currently stored."

}

#main starts here

echo "Welcome to version 3.1"
echo "Initilising variables"
echo ""

#CF = Client File
#BS = Backup Folder
#D = Dry-run
CF_ARG=0
CF_VAL=
BF_ARG=0
BF_VAL=
D_ARG=0

parseArgs $*
PARGS=$?

if [ $PARGS -eq 0 ]; then

        echo "Reading client file " $CF_VAL
        echo "Reading backup folder " $BF_VAL
        processFolder $BF_VAL
        return $?

else
        return $PARGS
fi

So what im aiming to do is the commening at the top just inside of processFolder ()

Hope you guys can help here.....
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Script help required!

Hi there, i am trying to create a script that checks for the existence of users on the system, if they exist then their details should print on the screen with a message that the id is in use. I am having a bit of trouble with it. Any ideas? Cheers Kev! (8 Replies)
Discussion started by: kev112
8 Replies

2. Shell Programming and Scripting

script required

The line is like this +abc+def+mgh+ddsdsd+sa i.e. words seperated by +. There is a plus in the beginning. i want to conver this line to abc, def, mgh, ddsdsd, sa please provide the logic in the form of a shell script Thanks in advance (13 Replies)
Discussion started by: skyineyes
13 Replies

3. Shell Programming and Scripting

Getting required fields from a test file in required fromat in unix

My data is something like shown below. date1 date2 aaa bbbb ccccc date3 date4 dddd eeeeeee ffffffffff ggggg hh I want the output like this date1date2 aaa eeeeee I serached in the forum but didn't find the exact matching solution. Please help. (7 Replies)
Discussion started by: rdhanek
7 Replies

4. Shell Programming and Scripting

Help required to get a script

Hi Experts, I am very beginner in Bash Shell Scripting. Can anyone please guide me to create a script which should show the most busy file systems in sort basis as there are a lot of file systems on the server. I was told this task to be done by my IT lead and I must have to do this in... (3 Replies)
Discussion started by: naw_deepak
3 Replies

5. Shell Programming and Scripting

rsync backup mode(--backup) Are there any options to remove backup folders on successful deployment?

Hi Everyone, we are running rsync with --backup mode, Are there any rsync options to remove backup folders on successful deployment? Thanks in adv. (0 Replies)
Discussion started by: MVEERA
0 Replies

6. Shell Programming and Scripting

Help with Backup Shell Script for Network Device Configuration backup

HI all, im new to shell scripting. need your guidence for my script. i wrote one script and is attached here Im explaining the requirement of script. AIM: Shell script to run automatically as per scheduled and backup few network devices configurations. Script will contain a set of commands... (4 Replies)
Discussion started by: saichand1985
4 Replies

7. UNIX for Dummies Questions & Answers

Perl Script:how to find how many parameters are required to run the script

How to find how many parameters are required to run a Perl script? (1 Reply)
Discussion started by: Lakshman_Gupta
1 Replies

8. AIX

GTAR - new ways for faster backup - help required

We are taking backup of our application data(cobol file system, AIX/unix) before and after EOD job runs. The data size is approximately 260 GB in biggest branch. To reduce the backup time, 5 parallel execution is scheduled through control-m which backups up the files in 5 different *.gz. The job... (2 Replies)
Discussion started by: Bharath_79
2 Replies

9. AIX

GTAR - new ways to faster backup - help required

We are taking backup of our application data(cobol file system, AIX/unix) before and after EOD job runs. The data size is approximately 260 GB in biggest branch. To reduce the backup time, 5 parallel execution is scheduled through control-m which backups up the files in 5 different *.gz. The job... (8 Replies)
Discussion started by: Bharath_79
8 Replies

10. Shell Programming and Scripting

Help required to get a backup script working

Hi all I have a unix based firewall, which creates a daily backup file on the device. I need a script to scp this file over to a remote server. I can get this working daily using a basic script and a cron job. However, I only want it to send the latest config back up file and currently... (4 Replies)
Discussion started by: jimmyzoom
4 Replies
All times are GMT -4. The time now is 11:30 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy