Download your favorite Linux distribution at LQ ISO.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 03-26-2008, 10:25 AM   #1
Registered: Nov 2006
Posts: 136

Rep: Reputation: 15
Backup Script

I have a backup script here at work on a server that will backup whats needed from the server to an external drive. Now everything works great but there are a few things Id like to build into it but have no clue how. This isnt my script (its a past employees) all I have done is minor modifications as needed. The two things I would like to do is this...
This is after a full system backup has already been made nd will run once a day.
1) If a file gets deleted from the server then delete it from the external drive.
2) If a file is updated on the server then update on the external drive.
3) If possible perhaps alter the script to run something that ONLY updates the external (delete files or update them)as to what ever changes have been made to the server.

Is any of this possible and if so how could I do it. Like I said I have never done any kind of programming on linux or any heavy commands, so help on this would be greatly appreciated. Here is the script I have now to JUST run a back up.

mount /dev/sdb1 /mnt/backup
tar -cvf /mnt/backup/etc.tar etc
tar -cvf /mnt/backup/scooter.tar /u /var/www /d2a /etc /home /var/lib/mysql backup backup1
cp /data/* /mnt/backup
cp backup /mnt/backup
cp backup1 /mnt/backup

mount win2:/ /win2 -o rsize=1024,wsize=1024
tar -cvf /mnt/backup/win2.tar /win2/u /win2/var/www /win2/etc

df -H
ls -al /mnt/backup
umount /win2
df -H
umount /mnt/backup
echo Done with Backup
Old 03-26-2008, 10:40 AM   #2
Registered: Apr 2006
Location: UK
Distribution: Mandriva, Debain, Redhat, Fedora, Ubuntu, FreeBSD
Posts: 269

Rep: Reputation: 30
all you really need is rsync it does wonders really
it synchronizes folders and files and if the is no changes it wont do anything
mount /dev/sdb1 /mnt/backup
rsync -vaz --delete --exclude="folder1" --exclude="folder2" /the/folder/ /destination/
exclude the folder u dont want to backup add what you want basically this is just a guide on
what you should use

Last edited by mahmoud; 03-26-2008 at 11:11 AM.
Old 03-26-2008, 10:44 AM   #3
Registered: Feb 2005
Distribution: Ubuntu, CentOS
Posts: 585

Rep: Reputation: 35
Suggestion 1: Deal With Pieces

Aside from your stress level going up, this is one of the best ways to get involved. Assuming your being in a Linux forum this script is written in bash. So, I would suggest you need a bash scripting guide, regardless of your level of experience. O'Reilly's guide is good, and Linux Shell Scripting With Bash by Ken O. Burtch Prentice/Hall is pretty good, too.

I strongly suggest that you write stub code (a script or program that accomplishes one thing, as a teaching tool) to try out one idea, and then incorporate into the main script. If you start by tackling individual pieces and posting those questions, helping you could be managed better, IMHO. Let's take your deleting a currently deleted file from the backup drive.

Are you wanting to delete that file from a tar archive? I suppose it could be done by looking for the file using tar t; unpacking the tar file in a sandbox; deleting the file; and making a tar file of what's left.

Last edited by cmnorton; 03-26-2008 at 10:45 AM. Reason: spelling
Old 03-26-2008, 10:46 AM   #4
Registered: May 2003
Location: West Midlands, United Kingdom.
Distribution: Slackware 14.1
Posts: 261

Rep: Reputation: 32

Not an expert by any means but I too have a backup script that basically updates a tar archive (removes deleted files, includes updated files, etc) then burns the whole image to DVD.

I believe what you are missing is rsync. This is the key to update/remove files from the archive.

Here is my script as it stands, hope it points you in the right direction...

##### rsync a=archive mode, x=one file system v=verbose ####
rsync -axv --delete --exclude-from=/home/mrt/documents/backup/exclude.txt /home/mrt/.kde/share/apps/kmail/mail /home/mrt/documents /etc/rc.d/rc.firewall /usr/local/etc/pdnsd.conf /etc/samba/smb.conf /etc/cups/cupsd.conf /bin/wipe /bin/daily-backup /bin/daily-backup2 /home/mrt/tmp 1> /home/mrt/documents/backup/backup.log

#### growisofs, front end to cdrecord adding dvd capabilities ####
#### -Z=initital data, -R=generate Rockridge extensions, joliet-long=generate joliet long extensions ####
#### -use-the-force-luke=tty=the only way to over write a dvd already containing data ####
/usr/local/bin/growisofs -Z  /dev/sr0 -use-the-force-luke=notray -use-the-force-luke=tty -use-the-force-luke=tracksize:1616633 -speed=4 -use-the-force-luke=bufsize:32m -R -joliet-long /home/mrt/tmp

#### clear up tmp file
rm -R -f /home/mrt/tmp
Hope that helps a little, BashTin
Old 03-26-2008, 11:07 AM   #5
LQ Addict
Registered: Jul 2002
Location: East Centra Illinois, USA
Distribution: Debian stable
Posts: 5,891

Rep: Reputation: 351Reputation: 351Reputation: 351Reputation: 351
Your script will not accomplish 1) or 2) unless you include the means of extracting the archive, synching the files, and remaking the tar archive.

I respectfully suggest that before you go any further, do some homework in re backups. is a good place to start reading.

When you have done the reading, then look over some extant applications for making network backups, which you can find at
Old 03-26-2008, 11:35 AM   #6
Registered: Nov 2006
Posts: 136

Original Poster
Rep: Reputation: 15
Wow thanks for all the replies. I will take a look into rsync along with the other suggestions. Thanks again.
feel free to post any other suggestions if there are others.

EDIT: I am running FC7 so from what I can tell (using "yum search rsync") rsync is already installed.
I will have to play with it and see what I can come up with

Last edited by crazy8; 03-26-2008 at 01:53 PM.


backup, rsync, tar

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
Backup script rcmonroig Linux - Newbie 4 04-21-2007 12:58 AM
Backup script raptorman Programming 4 08-22-2005 09:52 AM
What backup script do you use? buldir Linux - Software 1 04-12-2005 02:57 PM
Need a backup script enygma Linux - General 5 11-04-2004 03:49 PM
backup script ixion Linux - Software 2 01-09-2003 06:39 AM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 08:24 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration