GeneralThis forum is for non-technical general discussion which can include both Linux and non-Linux topics. Have fun!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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"
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.
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.
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
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.