LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Backup Script (https://www.linuxquestions.org/questions/linux-newbie-8/backup-script-630794/)

crazy8 03-26-2008 10:25 AM

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
echo Done with Backup
echo

mahmoud 03-26-2008 10:40 AM

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
try
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

cmnorton 03-26-2008 10:44 AM

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.

BashTin 03-26-2008 10:46 AM

Hi.

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

Code:

##### 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

bigrigdriver 03-26-2008 11:07 AM

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. http://www.linux-backup.net/ 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 http://www.linux.org/apps/all/Admini...on/Backup.html.

crazy8 03-26-2008 11:35 AM

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


All times are GMT -5. The time now is 06:19 PM.