LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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 10-30-2007, 03:59 PM   #1
Meson
Member
 
Registered: Oct 2007
Distribution: Arch x86_64
Posts: 606

Rep: Reputation: 66
Please critique my backup script


Hey, I just wrote my first backup script and I'd like some suggestions. Especially in the way I access the windows share. Is there a more direct approach than mounting the share separately?
Code:
#!/bin/bash
#Backup User's stuff onto Office share
#This should be run using sudo

destination_user=USER
source=/home/USER
destination_share=//192.168.1.111/User$ #This is a windows share
destination=/mnt/location
backup=$destination/BACKUP

#toggle verbose
#verbose=""
verbose="-v -v --progress"

#Handle backups
backup_suffix="__$(date +%Y.%m.%d-%H.%M.%S)"
backup_pattern="*__[0-9][0-9][0-9][0-9].[0-1][0-9].[0-3][0-9]-[0-2][0-9].[0-5][0-9].[0-5][0-9]"

#connect to the network share
mount -t cifs $destination_share $destination -o user=$destination_user

#FIREFOX THUNDERBIRD PIDGIN
# Mirror these things on the destination, inlcuding deletions.
# No backups are wanted.
options1="--recursive --times --delete-after --no-whole-file $verbose"
rsync $options1 $source/.mozilla/firefox/ $destination/Programs/FF_Profile/
rsync $options1 $source/.mozilla-thunderbird/ $destination/Programs/TB_Profile/
rsync $options1 $source/.purple/ $destination/Programs/P_Profile/

#DOCUMENTS PICTURES SCRIPTS
# Mirror these things on the destination.
# Move deletions/modifications to BACKUP folder and append a suffix.
# Ignores annoying windows system files.
options2="--recursive --times --no-whole-file --delete --backup --suffix=$backup_suffix $verbose --exclude=Thumbs.db --exclude=Desktop.ini"
rsync $options2 --backup-dir=$backup/Documents/ $source/Documents/ $destination/Documents/
rsync $options2 --backup-dir=$backup/Pictures/ $source/Pictures/ $destination/Pictures/
rsync $options2 --backup-dir=$backup/Scripts/ $source/scripts/ $destination/Programs/Scripts/

#MUSIC VIDEOS
# Copy new stuff to destination.
# Leave deletions in place, append suffix.
# Ignores previously backed up files.  Ignores annoying windows system files.
options3="--recursive --times --no-whole-file --delete --backup --suffix=$backup_suffix $verbose --exclude=$backup_pattern --exclude=Thumbs.db --exclude=Desktop.ini"
rsync $options3 $source/Music/ $destination/Music/
rsync $options3 $source/Videos/ $destination/Videos/

#SPECIAL FILES
# Backup these files to BACKUP directory and append suffix.
options4="--recursive --times --whole-file --delete --backup --suffix=$backup_suffix $verbose"
rsync $options4 --backup-dir=$backup $source/Database.kdb $destination/Database.kdb
#rsync $options4 --backup-dir=$backup $source/dat $destination/dat

#disconnect the network share
umount $destination_share
Thanks in advance!
 
Old 10-31-2007, 12:15 PM   #2
custangro
Senior Member
 
Registered: Nov 2006
Location: California
Distribution: Fedora , CentOS , Solaris 10, RHEL
Posts: 1,933
Blog Entries: 1

Rep: Reputation: 188Reputation: 188
Since you want it to run with sudo (root privileges) you should do:

Code:
if [ $(id -u) -ne 0 ]; then
  echo "Must be root to execute"
  exit
fi
Put that right after your variables...also (just my own personal preference), I always use ${variable} for my variables...they are just easier to see that way (IMO). Happy scripting

Last edited by custangro; 10-31-2007 at 12:18 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 On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: A critique of Open Source LXer Syndicated Linux News 0 08-27-2007 05:40 AM
code critique? a better way? dave201 Programming 8 06-25-2007 04:32 AM
Iptables Critique Centinul Linux - Security 2 08-09-2005 10:03 AM
New iptables configuration critique gizza23 Linux - Networking 11 08-06-2005 10:05 PM
Partitioning Critique Wanted Skazi Slackware 7 08-11-2004 02:20 PM


All times are GMT -5. The time now is 06:32 AM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration