LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > General
User Name
Password
General This forum is for non-technical general discussion which can include both Linux and non-Linux topics. Have fun!

Notices


Reply
  Search this Thread
Old 12-26-2006, 03:41 PM   #1
PatrickMay16
Member
 
Registered: Apr 2005
Location: London, England.
Distribution: Debian oldstable
Posts: 56

Rep: Reputation: 53
Backup shell script: help me improve it?


Hey guys. I don't know much about bash or shell scripting, but I knew just enough to make this shell script, which automates my weekly backup process. Though since I don't know very much, I thought I'd ask people here... is there anything pretty odd about my method? Is there any way that it can be improved? I'd be very happy to hear anything anyone has to say about this.

Here it is:

Code:
echo "beginning"
export NUTLOADER=`date +%a%d%b%Y`
cd ~/
mkdir ~/Desktop/autobackup-$NUTLOADER

####

echo "making texts backup" 
cd ~/
tar cvf texts.tar texts/
rar a texts.rar texts.tar
rm texts.tar
mv texts.rar ~/Desktop/autobackup-$NUTLOADER

####

echo "making webpages backup"
cd ~/
tar cvf webpagesbackup.tar Webpages
rar a webpagesbackup.rar webpagesbackup.tar
rm webpagesbackup.tar
mv webpagesbackup.rar ~/Desktop/autobackup-$NUTLOADER

####

echo "making zsnes backup"
cd ~/.zsnes/
tar cvf zsnesbackup.tar *.zs* *.sp* *.srm *.cfg
7z a zsnesbackup.7z zsnesbackup.tar 
rm zsnesbackup.tar
mv zsnesbackup.7z ~/Desktop/autobackup-$NUTLOADER

####

echo "making epsxe savestate backup"
cd ~/snes9x/epsxe/
tar cvf epsxe_sstate_backup.tar sstates/
rar a epsxe_sstate_backup.rar epsxe_sstate_backup.tar
rm epsxe_sstate_backup.tar
mv epsxe_sstate_backup.rar ~/Desktop/autobackup-$NUTLOADER

####

echo "making MIDI music backup"
cd ~/
7z a midistuff_backup.7z midifiles/ rosegardenfiles/
mv midistuff_backup.7z ~/Desktop/autobackup-$NUTLOADER

####

echo "done, check if everything worked"
 
Old 12-26-2006, 04:45 PM   #2
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682
Most backup scripts that I have seen use the find command to locate files modified since the last backup and use that list to create a tar file. The current date is used in the tar archive's file name.

You are using 3 different types of archive formats, some which aren't very common to Unix/Linux, may not be stable or have license or patent issues which may make them difficult to obtain in the future. Do 7z and rar understand Linux permissions. If they aren't GNU licensed, will they be available in the future?

IMHO, possibly using find to locate files modified after a certain date, and using tar to archive those files would work out better.

There are tar like alternatives. Dar which backs up to disc instead of tape. It also has a gui front end (kdar) that you can use to set it up. Then export a script to use in a cron job. ( Note: cron scripts don't use echo as your script does, but may keep a log file ).

If your filesystem supports ACLs, then you may want to use the "star" program instead. It will backup the security attributes and special permissions of files as well.

These are just my 2 cents worth. Using one archive format, and writing a cron friendly script may work out better.

Last edited by jschiwal; 12-26-2006 at 04:46 PM.
 
Old 12-26-2006, 05:23 PM   #3
PatrickMay16
Member
 
Registered: Apr 2005
Location: London, England.
Distribution: Debian oldstable
Posts: 56

Original Poster
Rep: Reputation: 53
Thanks for the reply.

Quote:
You are using 3 different types of archive formats, some which aren't very common to Unix/Linux, may not be stable or have license or patent issues which may make them difficult to obtain in the future. Do 7z and rar understand Linux permissions. If they aren't GNU licensed, will they be available in the future?
They aren't GNU licensed, as far as I know. But I've considered that problem; in the case of that event, I have backed up the latest versions of rar and 7z available for linux.
I don't know if they work with unix permissions, but that mostly doesn't matter to me; I can just make a tar archive and compress it with 7z or rar if I need to keep the permissions intact (and a lot of the time, this seems to result in the archive compressing better).
My reasons for using rar and 7z is that they compress very well.
 
Old 12-26-2006, 06:55 PM   #4
trickykid
LQ Guru
 
Registered: Jan 2001
Posts: 24,149

Rep: Reputation: 269Reputation: 269Reputation: 269
Quote:
Originally Posted by jschiwal
Most backup scripts that I have seen use the find command to locate files modified since the last backup and use that list to create a tar file. The current date is used in the tar archive's file name.
That's where rsync comes handy, no need to find and compare, rsync does it for you.

But If he's doing weekly backups, he really doesn't need to do an incremental as a weekly backup usually does a full backup.

Here's an example script I use to do full weekly backups of one of my systems:

Code:
#!/bin/bash
#
# System Backup Script.

host=`hostname -s`
date=$(date +%F)
filename=$host.$date

cd /
tar cf /backup/weekly/$filename.tar /boot /etc /usr/local/bin /var/named /home
gzip /home/backup/weekly/$filename.tar
sleep 2

exit 0
And here's an example script of my daily incremental's for my home directories since they're most likely to change the most often:

Code:
#!/bin/bash

PATH=/bin:/usr/bin
BACKUPDIR=/home/backup/daily

cd $BACKUPDIR
OPTS=" --delete --exclude cache --exclude Cache --exclude picKLE-cache"

TODAY=`date +%d%b%y`
YESTERDAYDIR=`/bin/ls -lrt | grep ^d | tail -1 | awk '{print $NF}'`

#echo $YESTERDAYDIR

if [ $YESTERDAYDIR != $TODAY ]
then
  cp -al $YESTERDAYDIR $TODAY
else
 echo Retrying Unfinished Backup
fi

rsync $OPTS -a /home /$BACKUPDIR/$TODAY

# Make $TODAY the most recently modified directory
# so it will be easily found tomorrow
touch $BACKUPDIR
touch $BACKUPDIR/$TODAY
 
  


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
shell backup script xtremeclones Linux - Software 3 10-03-2006 02:13 PM
Shell Script for backup BBQ_Matt Linux - Software 7 06-30-2005 05:19 PM
Incremental Backup shell script. datadriven Linux - General 3 06-02-2004 09:19 AM
writting a backup shell script yenonn Slackware 2 03-18-2004 07:49 PM
bash shell backup script turnip Programming 0 04-03-2003 06:00 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > General

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