LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 08-29-2012, 07:21 AM   #1
shubhamuddu
LQ Newbie
 
Registered: Jun 2012
Posts: 24

Rep: Reputation: Disabled
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,
 
Old 08-29-2012, 07:29 AM   #2
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fedora-35
Posts: 5,313

Rep: Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918
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

Last edited by schneidz; 08-29-2012 at 07:31 AM.
 
Old 08-30-2012, 04:23 AM   #3
shubhamuddu
LQ Newbie
 
Registered: Jun 2012
Posts: 24

Original Poster
Rep: Reputation: Disabled
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
 
Old 08-30-2012, 07:29 AM   #4
shubhamuddu
LQ Newbie
 
Registered: Jun 2012
Posts: 24

Original Poster
Rep: Reputation: Disabled
Can anybody please suggest something..
 
Old 08-30-2012, 08:49 AM   #5
konsolebox
Senior Member
 
Registered: Oct 2005
Distribution: Gentoo, Slackware, LFS
Posts: 2,248
Blog Entries: 8

Rep: Reputation: 235Reputation: 235Reputation: 235
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
 
  


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
how to create daily incremental backups easily? crypted Linux - Server 13 12-12-2010 02:41 AM
(Solved) Daily backups on USB device. antechrist Linux - Security 2 08-16-2010 05:01 AM
Tape Backups and How can i find out the Name (label) of the tape in the drive?? helptonewbie Linux - Newbie 2 10-27-2008 07:20 AM
postgres daily/weekly/ automated backups sir-lancealot Linux - Server 1 05-13-2008 07:00 PM
bacula - How do I setup up tape daily tape changes neocontrol Linux - Software 3 01-23-2008 09:27 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 07:28 PM.

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