Newbie Backup Script

 
Thread Tools Search this Thread
Operating Systems OS X (Apple) Newbie Backup Script
# 1  
Old 08-18-2011
Newbie Backup Script

Hello All,

I have attempted to write my first complex (to me) backup script. I am offering it to any and all who may find it useful but would like to refine it as well. I'm using it to backup a Mac OSX Lion Server to a USB Raid5. The script is actually comprised of a daily and a weekly script called by a plist file. Please provide any and all comments, corrections etc. Thanks in advance
Code:
#!/bin/sh
## DAILY BACKUP
##
Source1=/Volumes/Data/Aperture_Share
Source2=/Volumes/Data/iTunes_Share
Source3=/Volumes/Data/Public
Source4=/Users/admin
Destination=/Volumes/Backup/MediaServer/
Excludes=/Volumes/Backup/MediaServer/excludes.txt
Logfile=/Volumes/Backup/MediaServer/daily_logs/dailylog.txt
Logfilegzip=/Volumes/Backup/MediaServer/daily_logs/dailylog.txt.gz
##
diskutil mount /dev/disk3s2
echo "#######################################" >>$Logfile 
echo "***************************************" >>$Logfile
echo "~~~~~~~~Starting Daily Backup~~~~~~~~~~" >>$Logfile
date >>$Logfile
/usr/local/bin/rsync -avzxpP --stats --exclude-from=$Excludes $Source1 $Source2 $Source3 $Source4 $Destination/current/ >>$Logfile
date >>$Logfile
echo "~~~~~~~~Finished Daily Backup~~~~~~~~~~" >>$Logfile
echo "***************************************" >>$Logfile
echo "#######################################" >>$Logfile
##
gzip $Logfile
cp $Logfilegzip /Volumes/Backup/MediaServer/daily_logs/"`date +%m%d%y`_dailylog.txt.gz"
uuencode $Logfilegzip $Logfilegzip | mailx -s "Daily MediaServer Backup" user@gmail.com
rm $Logfilegzip
sleep 20
diskutil umount /dev/disk3s2
##

Code:
#!/bin/sh
## WEEKLY BACKUP
##
Source1=/Volumes/Data/Aperture_Share
Source2=/Volumes/Data/iTunes_Share
Source3=/Volumes/Data/Public
Source4=/Users/admin
Destination=/Volumes/Backup/MediaServer/
Excludes=/Volumes/Backup/MediaServer/excludes.txt
Logfile=/Volumes/Backup/MediaServer/weekly_logs/weeklylog.txt
Logfilegzip=/Volumes/Backup/MediaServer/weekly_logs/weeklylog.txt.gz
##
diskutil mount /dev/disk3s2
echo "#######################################" >>$Logfile
echo "***************************************" >>$Logfile
echo "~~~~~~~Starting Weekly Backup~~~~~~~~~~" >>$Logfile
date >>$Logfile
/usr/local/bin/rsync -avzxpP --stats --exclude-from=$Excludes $Source1 $Source2 $Source3 $Source4 $Destination/current/ >>$Logfile  
rm -rf $Destination/snapshot.3   
mv $Destination/snapshot.2 $Destination/snapshot.3  
mv $Destination/snapshot.1 $Destination/snapshot.2 
mv $Destination/snapshot.0 $Destination/snapshot.1 
cd $Destination/current
find . -print | cpio -dumpvl $Destination/snapshot.0
/usr/local/bin/rsync -avzxpP --stats --delete --exclude-from=$Excludes $Source1 $Source2 $Source3 $Source4 $Destination/current/ >>$Logfile  
date >>$Logfile
echo "~~~~~~~~Finished Weekly Backup~~~~~~~~~" >>$Logfile
echo "***************************************" >>$Logfile
echo "#######################################" >>$Logfile
##
gzip $Logfile
cp $Logfilegzip /Volumes/Backup/MediaServer/weekly_logs/"`date +%m%d%y`_weeklylog.txt.gz"
uuencode $Logfilegzip $Logfilegzip | mailx -s "Weekly MediaServer Backup" user@gmail.com
rm $Logfilegzip
sleep 20
diskutil umount /dev/disk3s2
##


Last edited by zaxxon; 08-18-2011 at 10:24 AM.. Reason: scottn: Please use code tags, zaxxon: correcting line wrap
# 2  
Old 08-18-2011
I see posibly two issues; the device disk number could change and the uncanny ability of OS X to write directorties that aren't mount point to the /Volumes directory. So first I would query diskutil and mount for the proper device then run something like ->
Code:
for MNT in /Volumes/*
do
if [[ $(/usr/bin/stat -f "%d" "$MNT") = $(/usr/bin/stat -f "%d" "$MNT/..") ]]; then
 echo $MNT is NOT a file system mount point
fi
done


Last edited by xbin; 08-19-2011 at 10:29 AM..
# 3  
Old 09-06-2011
add this line to the top somewhere.
Quote:
# The script must be run as root
#
if [ "$USER" != "root" ]; then
echo "Must be run as root"
exit 1
fi
# 4  
Old 01-14-2012
Quote:
Originally Posted by dbol
Hello All,

I have attempted to write my first complex (to me) backup script. I am offering it to any and all who may find it useful but would like to refine it as well. I'm using it to backup a Mac OSX Lion Server to a USB Raid5. The script is actually comprised of a daily and a weekly script called by a plist file. Please provide any and all comments, corrections etc. Thanks in advance
Code:
#!/bin/sh
## DAILY BACKUP
##
Source1=/Volumes/Data/Aperture_Share
Source2=/Volumes/Data/iTunes_Share
Source3=/Volumes/Data/Public
Source4=/Users/admin
Destination=/Volumes/Backup/MediaServer/
Excludes=/Volumes/Backup/MediaServer/excludes.txt
Logfile=/Volumes/Backup/MediaServer/daily_logs/dailylog.txt
Logfilegzip=/Volumes/Backup/MediaServer/daily_logs/dailylog.txt.gz
##
diskutil mount /dev/disk3s2
echo "#######################################" >>$Logfile 
echo "***************************************" >>$Logfile
echo "~~~~~~~~Starting Daily Backup~~~~~~~~~~" >>$Logfile
date >>$Logfile
/usr/local/bin/rsync -avzxpP --stats --exclude-from=$Excludes $Source1 $Source2 $Source3 $Source4 $Destination/current/ >>$Logfile
date >>$Logfile
echo "~~~~~~~~Finished Daily Backup~~~~~~~~~~" >>$Logfile
echo "***************************************" >>$Logfile
echo "#######################################" >>$Logfile
##
gzip $Logfile
cp $Logfilegzip /Volumes/Backup/MediaServer/daily_logs/"`date +%m%d%y`_dailylog.txt.gz"
uuencode $Logfilegzip $Logfilegzip | mailx -s "Daily MediaServer Backup" user@gmail.com
rm $Logfilegzip
sleep 20
diskutil umount /dev/disk3s2
##

Code:
#!/bin/sh
## WEEKLY BACKUP
##
Source1=/Volumes/Data/Aperture_Share
Source2=/Volumes/Data/iTunes_Share
Source3=/Volumes/Data/Public
Source4=/Users/admin
Destination=/Volumes/Backup/MediaServer/
Excludes=/Volumes/Backup/MediaServer/excludes.txt
Logfile=/Volumes/Backup/MediaServer/weekly_logs/weeklylog.txt
Logfilegzip=/Volumes/Backup/MediaServer/weekly_logs/weeklylog.txt.gz
##
diskutil mount /dev/disk3s2
echo "#######################################" >>$Logfile
echo "***************************************" >>$Logfile
echo "~~~~~~~Starting Weekly Backup~~~~~~~~~~" >>$Logfile
date >>$Logfile
/usr/local/bin/rsync -avzxpP --stats --exclude-from=$Excludes $Source1 $Source2 $Source3 $Source4 $Destination/current/ >>$Logfile  
rm -rf $Destination/snapshot.3   
mv $Destination/snapshot.2 $Destination/snapshot.3  
mv $Destination/snapshot.1 $Destination/snapshot.2 
mv $Destination/snapshot.0 $Destination/snapshot.1 
cd $Destination/current
find . -print | cpio -dumpvl $Destination/snapshot.0
/usr/local/bin/rsync -avzxpP --stats --delete --exclude-from=$Excludes $Source1 $Source2 $Source3 $Source4 $Destination/current/ >>$Logfile  
date >>$Logfile
echo "~~~~~~~~Finished Weekly Backup~~~~~~~~~" >>$Logfile
echo "***************************************" >>$Logfile
echo "#######################################" >>$Logfile
##
gzip $Logfile
cp $Logfilegzip /Volumes/Backup/MediaServer/weekly_logs/"`date +%m%d%y`_weeklylog.txt.gz"
uuencode $Logfilegzip $Logfilegzip | mailx -s "Weekly MediaServer Backup" user@gmail.com
rm $Logfilegzip
sleep 20
diskutil umount /dev/disk3s2
##

# The script must be run as root
#
if [ "$USER" != "root" ]; then
echo "Must be run as root"
exit 1
fi
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. 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

2. Shell Programming and Scripting

Shell script newbie, what is problem with my script?

Hello, Ubuntu server 11.10 can anybody help what is problem with my shell script? #!/bin/bash #script to find out currently logged on user is root or not. if ] then echo "You are super" else echo "You are awesome!" fi When I run script, I get following output ./uid: line 3: I... (4 Replies)
Discussion started by: kaustubh
4 Replies

3. Shell Programming and Scripting

please help newbie with script

hi!i am musician and have very little knowledge about shell here's my script #!/bin/bash for (( ; ; )) do wget some wikipedia article here --output-document=- > /dev/audio done so it downloads random wikipedia page (forum doesnt let me post link so i wrote some wikipedia article here... (6 Replies)
Discussion started by: karlhungus
6 Replies

4. 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

5. Shell Programming and Scripting

Newbie wanting help with a script

Hi I am new to scripting and having trouble with an assignment. I have written this script: #!/bin/bash PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin printf "\nWhat is the name of the input file? " read INPUT_FILE if test ! -f ./$INPUT_FILE ; then printf "\nNo matching file... (2 Replies)
Discussion started by: foyn
2 Replies

6. Shell Programming and Scripting

Newbie needs help with ping script

Hi all, I've been trying to get this script right for the past few days and just can't figure out where I'm going wrong. Since one of my internet connections is extremely flaky I want to run this script to ping every 5 minutes and then reboot the router via telnet if I don't get a response. ... (5 Replies)
Discussion started by: goatmilk
5 Replies

7. Shell Programming and Scripting

Expect script help (newbie)

Im a UNIX newbie so please excuse the little knowledge I have, Im trying to learn. I created a script that logs into multiple servers, gets data and saves it on the local server. The script looks like this.. #!/opt/local/bin/expect # Set username/password to initially login to switch.... (4 Replies)
Discussion started by: jay11789
4 Replies

8. Shell Programming and Scripting

Newbie Question - Help with script

Hi I have about 5000 expired images that need removed from disk. Instead of doing it manually I am trying to use the following script: #vi remove_expired_images FilePath=/Scripts for i in `cat $FilePath/backupid.txt` do #echo $i >> $FilePath/Jim.txt... (2 Replies)
Discussion started by: jamba1
2 Replies

9. Shell Programming and Scripting

Help - shell script newbie

My problem looks like it should have a simple solution but it seems that after many days of research I cannot find a good solution. What I have is an input file that contains lines of information. What I need is to extract specific information from that file. What I know is that somewhere in the... (2 Replies)
Discussion started by: eback
2 Replies

10. Solaris

Solaris 7 newbie tape backup question

Hello all, I have an ss20 running Solaris 7, with an attached 4mm tape drive. The machine has one 1.2GB SCSI HDD. I would like to backup other machines to tape, but I can't do a stopover on the ss20s hard disk, as there is virtually no space available. Is there a way I can make the tape... (5 Replies)
Discussion started by: jolok
5 Replies
Login or Register to Ask a Question