LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Moving backups to tape daily (https://www.linuxquestions.org/questions/linux-newbie-8/moving-backups-to-tape-daily-4175424576/)

shubhamuddu 08-29-2012 07:21 AM

Moving backups to tape daily
 
Hello..



I scheduled database bakups to be created on disk with date format on daily basis.

I want to move these directories to tape safely.


Will the below script does this job well for me.
Please correct and advice if anything is missing.


# Backup logs are stored here
LOGBASE=/root/backup/log

# Get todays day like Mon, Tue and so on
TODAY=$(`date +%d%b`)

# Backup dirs; do not prefix /
BACKUP_ROOT_DIR="u04/Backup/Flash/rman_*_$TODAY"

# Tape device name
TAPE="/dev/IBMtape0"

# Exclude file
TAR_ARGS=""
EXCLUDE_CONF=/root/.backup.exclude.conf

# Backup Log file
LOGFIILE=$LOGBASE/$TODAY.backup.log

# Path to binaries
TAR=/bin/tar
MT=/bin/mt
MKDIR=/bin/mkdir

# ------------------------------------------------------------------------
# Excluding files when using tar
# Create a file called $EXCLUDE_CONF using a text editor
# Add files matching patterns such as follows (regex allowed):
# home/vivek/iso
# home/vivek/*.cpp~
# ------------------------------------------------------------------------
[ -f $EXCLUDE_CONF ] && TAR_ARGS="-X $EXCLUDE_CONF"

#### Custom functions #####
# Make a full backup
full_backup(){
local old=$(pwd)
cd /
$TAR $TAR_ARGS -cvzpf $TAPE $BACKUP_ROOT_DIR
$MT -f $TAPE rewind
$MT -f $TAPE offline
cd $old
}


# Make sure all dirs exits
verify_backup_dirs(){
local s=0
for d in $BACKUP_ROOT_DIR
do
if [ ! -d /$d ];
then
echo "Error : /$d directory does not exits!"
s=1
fi
done
# if not; just die
[ $s -eq 1 ] && exit 1
}

#### Main logic ####

# Make sure log dir exits
[ ! -d $LOGBASE ] && $MKDIR -p $LOGBASE

# Verify dirs
verify_backup_dirs

# Okay let us strat backup procedure
case $TODAY in
Sun|Tue|Wed|Thu|Fri|Sat) full_backup;;
*) ;;
esac > $LOGFIILE 2>&1


Thanks $ Regards,

schneidz 08-29-2012 07:29 AM

i get this when i run your date command:
Code:

date +%d%b
29Aug

so it will never equal sunday, monday, tuesday, ...

this mite be what you want:
Code:

date +%a
Wed


shubhamuddu 08-30-2012 04:23 AM

Hi ...

Thanks,
See the below backup directories for more info.
will the script understand the following command to pickup these backup directories ..?

# Backup dirs; do not prefix /
BACKUP_ROOT_DIR="u04/Backup/Flash/rman_*_$TODAY"

[oraprod@prod Flash]$ pwd
/u04/Backup/Flash
[oraprod@prod Flash]$ ls -lrt
total 16
drwxr-xr-x 2 oraprod dba 4096 Aug 26 00:45 rman_full_bkp_26Aug
drwxr-xr-x 2 oraprod dba 4096 Aug 28 00:50 rman_daily_incr_28Aug
drwxr-xr-x 2 oraprod dba 4096 Aug 29 00:45 rman_ctv_29Aug
drwxr-xr-x 2 oraprod dba 4096 Aug 30 00:46 rman_daily_incr_30Aug

Rgrds,
Shubha

shubhamuddu 08-30-2012 07:29 AM

Can anybody please suggest something..

konsolebox 08-30-2012 08:49 AM

Since it only has a function that targets full backup, does this imply that you're only after rman_full_bkp_* dirs?

As suggested by Schneidz, you should use this something like this instead:
Code:

case "$(date +%a)" in
or
Code:

TODAY=$(`date +%d%b`)
TODAY_DOTW=$(date +%a)
...
case "$TODAY_DOTW" in
...

It's a little confusing but this is how I could see things so far:
Code:

#!/bin/bash

# Backup logs are stored here

LOGBASE=/root/backup/log

# Get todays day like Mon, Tue and so on
TODAY=$(`date +%d%b`)
TODAY_DOTW=$(date +%a)

# Backup dirs; do not prefix /
BACKUP_ROOT_DIRS=(u04/Backup/Flash/rman_*_"$TODAY")

# Tape device name
TAPE="/dev/IBMtape0"

# Exclude file
TAR_ARGS=()
EXCLUDE_CONF=/root/.backup.exclude.conf

# Backup Log file
LOGFIILE=$LOGBASE/$TODAY.backup.log

# Path to binaries
TAR=/bin/tar
MT=/bin/mt
MKDIR=/bin/mkdir

# ------------------------------------------------------------------------
# Excluding files when using tar
# Create a file called $EXCLUDE_CONF using a text editor
# Add files matching patterns such as follows (regex allowed):
# home/vivek/iso
# home/vivek/*.cpp~
# ------------------------------------------------------------------------
[ -f "$EXCLUDE_CONF" ] && TAR_ARGS=(-X "$EXCLUDE_CONF")

#### Custom functions #####
# Make a full backup
full_backup() {
        local old=$(pwd)
        cd /
        "$TAR" "${TAR_ARGS[@]}" -cvzpf "$TAPE" "$BACKUP_ROOT_DIRS" ## ????
        "$MT" -f "$TAPE" rewind
        "$MT" -f "$TAPE" offline
        cd "$old"
}


# Make sure all dirs exits
verify_backup_dirs() {
        local s=0
        for d in "${BACKUP_ROOT_DIRS[@]}"; do
                if [ ! -d "/$d" ]; then
                        echo "Error : /$d directory does not exits!"
                        s=1
                fi
        done
        # if not; just die
        [ "$s" -eq 1 ] && exit 1
}

#### Main logic ####

# Make sure log dir exits
[ ! -d "$LOGBASE" ] && "$MKDIR" -p "$LOGBASE"

# Verify dirs
verify_backup_dirs

# Okay let us strat backup procedure
case "$TODAY_DOTW" in
Sun|Tue|Wed|Thu|Fri|Sat)
        full_backup
        ;;
*)
        ;;
esac >"$LOGFIILE" 2>&1



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