OpenSUSE Linux Rants

OpenSUSE Linux Tips, tricks, how-tos, opinions, and news

My Resume  -  My LinkedIn Profile

January 9, 2007

Backing It Up Linux-style

by @ 9:06 am. Filed under bash, freebies

Here we go with another semester of school. Could someone please take a belt sander to my eyeballs?

At work, we have a script that I wrote for backing up our files, code, and data. It is actually one script for the filesystem backups, and one script for the database backups.

I am providing the filesystem backup script here in hopes that it may be of help to someone.

That said, let me tell you a little about it.

This script is meant to perform both full backups and incremental daily backups of a directory and all contents. It creates a bzipped tarball of it and then copies it over to a CIFS share. In our case, our tape backup is on the machine with the CIFS share.

How hard is it to run tar and then cp? It isn’t. What is harder is completely automating the entire process and taking close care to watch the success of every step. It should never fail, but if something does, retry a certain number of times. Log all steps and their outcome to a log file. When the script finishes, email the last 50 lines of the log to the system administrator.

Every step is verified. Meaning that any time a file is copied, the source and destination files are checked to make sure they are identical. Any time any command is executed, the return code is checked to make sure what we think should have happened is what actually happened.

It is pretty robust, and hasn’t even blinked since I gave my final approval to push it live. It could very easily be adapted to back stuff up to FTP or an NFS share or whatever else you need to back it up to.

If you would like to take a look, you can grab it here. Run it without any parameters to see how to use it. You will need to go into the script and put in the CIFS share, username, password, and local mount point. I was going to put everything on the commandline, but I was short on time, so I only put stuff on the command line that would change from machine to machine on our network. The CIFS share is always the same, so I just put that stuff directly into the script.

If you find it helpful, post a comment here and let me know.

4 Responses to “Backing It Up Linux-style”

  1. Viktor Says:

    Very interesting Scott, thanks for sharing that!

    I have a website with forums on a shared host, and have set up a script that takes a full database dump, tar bzips it, and emails it to me as an attachment. Its not the greatest way of doing it, but if anything happens I have a backup.

    Unfortunately, Gmail for some reason does not recognize it as an attachment, maybe the way I’m doing it.

    I’m doing

    #!/bin/bash

    DATE=`date +%y%m%d_%T`
    mysqldump -u username –password=password databasename > backup_$DATE
    gzip backup_$DATE
    uuencode backup_$DATE.gz backup_${DATE}_file.gz | mail -s Backup my-email@gmail.com

    I’m considering maybe setting up a remote backup script that uses rsync and cycles between 3 backup copies on the remote backup server, but well, I’m a little lazy 😛

  2. Scott Morris Says:

    You’re welcome. 🙂 Strange that gmail doesn’t like your attachments. Thanks for coming by.

  3. jj Says:

    Thanks… One of my New Years Resolutions is “BACK IT UP!!!”

  4. GN Says:

    great script Scott, I use it here with small modifications to it. I actually was about to write one myself, then I saw your blog on this, coincidence?

    Also, thanks for “helping” out on the new blog of Jeff Jaffe from Novell. I think it is you on the comment space hehehe 😉

OpenSUSE Linux Rants
Official OpenSUSE Linux Site

internal links:

categories:

SUSE Resources

search blog:

archives:

May 2021
S M T W T F S
« Feb    
 1
2345678
9101112131415
16171819202122
23242526272829
3031  

59 queries. 1.475 seconds