LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 03-06-2012, 03:41 PM   #1
ChrisDK
LQ Newbie
 
Registered: Mar 2012
Posts: 2

Rep: Reputation: Disabled
Need some shell script help


Hi all,

I'm currently working on a MySQL backup strategy plan and will need to run some scrips in cron to zip and move files to another server.

Here is my scenario:

I will be making incremental backups every 15 minutes using MySQL Enterprise Backup which creates a new directory in my backups folder. Once this backup is complete I can zip all other backups in the same directory and move them elsewhere. However I must always leave the latest backup.

Here is the pseudo code of the shell script I need:

//start script
//////////////////////
Get <last backup directory> name and store in variable

Create <new backup directory> and store in variable (yyyy-mm-dd_hh_mm_ss)

Run backup: MySQLBackup <last backup directory> <new backup name>

tar and gzip the <last backup directory>

move the <last backup directory> elsewhere

//End script
/////////////////////

The new backup directory is left alone for the next round.

The details I'm curious about are whether the script will need any IF conditions or LOOP conditions to satisfy the needs. Or can we use some fancy pipes with an ls command ?

Thanks in advance for any help someone can give.

Cheers,
Chris
 
Old 03-06-2012, 05:26 PM   #2
allend
LQ 5k Club
 
Registered: Oct 2003
Location: Melbourne
Distribution: Slackware64-15.0
Posts: 6,375

Rep: Reputation: 2754Reputation: 2754Reputation: 2754Reputation: 2754Reputation: 2754Reputation: 2754Reputation: 2754Reputation: 2754Reputation: 2754Reputation: 2754Reputation: 2754
This is some code from my weekly backup script that shows how I handle the <last backup directory> and create <new backup directory> with date and time information.

The actual backup code, tar and gzip and final move I leave as an exercise as it will be location dependent.

Note that this code contains echo statements, so when run from a cron job an email is generated to the user who launched the cron job.

Code:
#!/bin/bash
# Script to backup files to local directory from LAN PCs
#
# Intended to be run as a weekly cron job.
# Can also be run manually with a space separated list of 
#  machine names added to just backup from those machines.

# Where to backup to
LOCAL_DEST="/home/<username>/Desktop/Backups/"

# File to maintain the last backup date and time
# The file date and time can be changed with 'touch -t MMDDhhmm /var/bakup/lastPCFilesbakup'
LAST_BACKUP="/var/bakup/lastPCFilesbakup"

# Default list of machines to backup
MACHINES=( M540499 \
           M540500 \ 
         ) 

#***--- Create directory to contain backup
backup_begin() {
  # Directory under which to create backup  
  BACKUP_DIR_PREFIX=$LOCAL_DEST"/"$(date +%F)
  if [ ! -d $BACKUP_DIR_PREFIX ]; then
    mkdir -p $BACKUP_DIR_PREFIX
  fi
}

#***--- Get from PC M540499
backup_M540499() {
  # Code to perform backup
...
}
#***--- Get from PC M540500
backup_M540500() {
  # Code to perform backup
...
}
...
backup_begin
if [ $1 ]; then
  # Assume that additional parameters are machine names
  for PC in $@; do
    echo  "Started backup of "$PC" at "$(date)
    backup_$PC
  done;
else
  # No additional parameters, so use default list of machine names
  for PC in ${MACHINES[@]}; do
    echo  "Started backup of "$PC" at "$(date)
    backup_$PC
  done;
fi
# Remember this backup date and time
touch $LAST_BACKUP
 
Old 03-07-2012, 10:26 AM   #3
ChrisDK
LQ Newbie
 
Registered: Mar 2012
Posts: 2

Original Poster
Rep: Reputation: Disabled
Thanks for your time Allen.

I'm not sure if I'll be able to use any of your logic, but def. worth a look at how you're managing your backups.

-Chris
 
  


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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to pass command line arguments from one shell script to another shell script VijayaRaghavanLakshman Linux - Newbie 5 01-20-2012 09:12 PM
Shell Script running in another shell script and then exit dreamervlk Linux - General 3 09-16-2011 06:40 AM
Executing a Shell script with 654 permissions inside another shell script. changusee2k Linux - Newbie 2 06-07-2011 07:58 PM
shell script problem, want to use shell script auto update IP~! singying304 Programming 4 11-29-2005 05:32 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 04:39 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