LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 09-18-2003, 11:19 AM   #1
dopper
Member
 
Registered: Jun 2003
Location: Canada
Distribution: Muppy 006 (puppy 2.12 derivative) & Ubuntu 6.06 LTS Dapper Drake, ipcop 1.4.13
Posts: 52

Rep: Reputation: 15
shell scripts in linux


I'm using a script someone else wrote to do automated daily backup 'snapshots' of all the computers on my lan using ssh, cron, & rsync.

I have a directory with all my websites that I'd like to do snapshots of but I'd like to exclude all the subdirectories called 'extras' since all those dir's contain large .psd, .tif, .bmp & other large files not meant for the web. Is there a simple way to exclude all the 'extras' subdirs using the script below or is it a lot more involved than that?

#!/bin/sh -e

DIR_DATA="/opt/backup/remote-mount/SERVERNAME/SHARENAME"
DIR_BKUP_ROOT="/opt/backup/snapshot/SERVERNAME_SHARENAME"

# Assumes the existence of
#${DIR_BKUP_ROOT}/{Sunday,Monday,Tuesday,Wednesday,Thursday,Friday,Saturday}

RM="/bin/rm"
CP="/bin/cp"
RSYNC="/usr/bin/rsync"
DATE="/bin/date"

[ -x $RM -a -x $CP -a -x $RSYNC -a -x $DATE ] || exit 1

TODAY=`$DATE +%A`

case "$TODAY" in
'Monday')
LASTNIGHT="Sunday"
PREVBACK="Saturday"
;;
'Tuesday')
LASTNIGHT="Monday"
PREVBACK="Sunday"
;;
'Wednesday')
LASTNIGHT="Tuesday"
PREVBACK="Monday"
;;
'Thursday')
LASTNIGHT="Wednesday"
PREVBACK="Tuesday"
;;
'Friday')
LASTNIGHT="Thursday"
PREVBACK="Wednesday"
;;
'Saturday')
LASTNIGHT="Friday"
PREVBACK="Thursday"
;;
'Sunday')
LASTNIGHT="Saturday"
PREVBACK="Friday"
;;
*)
echo "ERROR: Invalid day!"
exit 2
;;
esac

$RM -rf ${DIR_BKUP_ROOT}/$LASTNIGHT
$CP -al ${DIR_BKUP_ROOT}/$PREVBACK ${DIR_BKUP_ROOT}/$LASTNIGHT
$RSYNC -avze --delete ${DIR_DATA}/ ${DIR_BKUP_ROOT}/${LASTNIGHT}/
 
Old 09-18-2003, 11:38 AM   #2
natma
LQ Newbie
 
Registered: May 2003
Location: France
Posts: 7

Rep: Reputation: 0
use the "--exclude" parameter of "rsync"
check "man rsync"
example:
the last line will become
-=-=-=-
$RSYNC -avz -e ssh --delete --exclude 'extras' ${DIR_DATA}/ ${DIR_BKUP_ROOT}/${LASTNIGHT}/
=-=-=-=

beware: all directories (and their subdirs) and files named "extras" will not be sync'ed


for another matter replace the whole "case" with:
LASTNIGHT=`date +%A -d yesterday`
PREVBACK=`date +%A -d "2 days ago"`
 
Old 09-18-2003, 03:06 PM   #3
dopper
Member
 
Registered: Jun 2003
Location: Canada
Distribution: Muppy 006 (puppy 2.12 derivative) & Ubuntu 6.06 LTS Dapper Drake, ipcop 1.4.13
Posts: 52

Original Poster
Rep: Reputation: 15
thanks

perfect, that's exactly what I wanted
 
Old 10-05-2003, 05:12 PM   #4
dopper
Member
 
Registered: Jun 2003
Location: Canada
Distribution: Muppy 006 (puppy 2.12 derivative) & Ubuntu 6.06 LTS Dapper Drake, ipcop 1.4.13
Posts: 52

Original Poster
Rep: Reputation: 15
.

Last edited by dopper; 10-05-2003 at 05:17 PM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
shell scripts newbie_m Linux - Newbie 3 01-18-2005 08:12 PM
Linux commands in shell scripts james_cwy Linux - Newbie 4 11-10-2003 01:14 AM
writing Linux shell scripts in Windows NightWolf_NZ Linux - Newbie 3 09-10-2003 09:28 PM
using shell scripts with modem under linux gkrumins Programming 2 06-06-2002 01:05 AM
Need Help with Shell Scripts!!!!!!!!!!! vicsharps Linux - Newbie 3 03-07-2002 09:05 PM


All times are GMT -5. The time now is 08:53 AM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration