#! /bin/bash # /usr/local/bin/Backup_1.0.8.sh # # See http://www.jperkins.us/computer/backups/ # Author: Jerry Perkins, Nashville, Tennessee # Last revision August 20, 2008 # Version 1.0.8 # # Purpose: To make incremental backups. # # --------- COMMENTS ---------------------- # # I burn the Monthly and Weekly backups to DVD. # # But the Hourly and Daily backups are cleaned out using # the cleanup script, Backup_Cleanup.sh. This script needs # to be configured. # # --------- SETUP ---------------------- # # Create a directory in your backup partition for # each of the periods that you will backup. Such as # Hourly, Daily, Weekly, Monthly. # # Save as this script to /usr/local/bin. Then copy to # the needed active scripts such as Backup_Hourly.sh, # Backup_Daily.sh, Backup_Weekly.sh, and Backup_Monthly.sh. # Make sure that each of this scripts is set as # exacutable. Then configure each script using the # Configure Section below. # # --------- CONFIGURE SECTION ---------- # # Set path to directory where to backups will be stored. # Examples: # STORAGE="/mnt/backups/Monthly" # STORAGE="/mnt/Big_Storage/Backups/Monthly" # STORAGE="/mnt/backups/To_DVD" STORAGE="/mnt/backups/test" # # # List the directories that are to be backed up. # Example, "/etc /home /usr/local" will backup everything # in /etc, /home and /usr/local. If you do /home/*, a # separate tar bar will be created for each # sub-directory in /home. # /etc - Low volumne. I run this on all, which has # gotten me out of jams. I use on all backups. # /home - For multi users use /home/*. A lot of traffic # from browser and email. I use on all backups. # /opt - May not need, but should check. # /root - Low traffic. I use on all backups. # /srv - Only if you use this. I have Samba shares and # web site. # /usr/local - All other /usr is static. This should # contain your local scripts, logs, etc. # /var - Will fill up with a lot of junk. But you may # want to capture weekly your MySQL. Also if you have your # web server running, /var/www. I do a daily /var/* just # to see the traffic volumne. # # You can also backup remote directories that are # mounted. Example shows a backup to a Microsoft # directory. WARNING, do not use directory names that # contain a space, such as "My Documents". But you can use # "My*". Warning, I have not tested the "*" since major # changes to script. There also can be security issues # with sharing Microsoft files. # PATHLIST="/mnt/c-drive/WINDOWS/Profiles /mnt/c-drive/WINDOWS/My*" # # Examples: # PATHLIST="/etc /home/* /root /srv/* /usr/local /var/*" # PATHLIST="/etc /home/ /opt /root /srv /usr/local /var/www" PATHLIST="/etc /home/* /root /srv/* /opt /usr/local /var/lib/mysql /var/www" # # # Tar ball pre-name. This puts a name or letter at the # beginning of the tar ball. # Hence file root_2008-08-20.tar.gz with PRE="Daily-" becomes # Daily-root_2008-08-20.tar.gz # Examples: # PRE="D-" # PRE="Weekly-" # PRE="" (To leave it empty) PRE="" # # # Set the time to be used: # minutes is "minute" # days is "day" TIMETYPE="minute" # # # Set the period of time between backups. If time is # in minutes, add one minute. # Note that the days goes till midnight. So that if you # do a daily backup 10 minutes after midnight and set PERIOD="-1" # you get only the last 10 minutes, so set PERIOD="-2". # For mid-day backup use minutes, hence MINDAY="-mmin" and # PERIOD="-1442" (24 hours times 60 minutes plus 2). For a weekly # backup in minutes use PERIOD="-10082" # Example: # PERIOD="-7" (for 7 days) # PERIOD="-121" (for 2 minutes) PERIOD="-121" # # # Set User Name. This the owner of each tar ball. FILEOWNER="root" # # # Set Group Name. This the group of each tar ball. FILEGROUP="js" # # # Set permissions. Suggest either 400 for owner read or # 440 for owner and group read. PERM="440" # # # --------- CRON NOTES ---------- # # Set each script to run in cron. # # # --------- NO EDITING BELOW THIS LINE ---------- # if [ $TIMETYPE == "day" ] then MINDAY="-mtime" DAYNAME=`date +%Y-%m-%d` else if [ $TIMETYPE == "minute" ] then MINDAY="-mmin" DAYNAME=`date +%Y-%m-%d-%H` else echo "Error in TIME variable."; echo "Needs to be \"day\" or \"minute\"."; exit fi fi FILEPOST=".tar.gz" DASH="_" if [ -e $STORAGE ] then cd $STORAGE for LIST in $PATHLIST do LISTROOT=`echo "$LIST" | colrm 1 1` DIRNAME=`echo "$LISTROOT"| sed "s/\//_/g"` FILENAME=$PRE$DIRNAME$DASH$DAYNAME$FILEPOST if [ -e $LIST ] then find $LIST $MINDAY $PERIOD -type f | tar zcfP $FILENAME -T- fi done CHGALL="*"$DAYNAME$FILEPOST chown $FILEOWNER $CHGALL chgrp $FILEGROUP $CHGALL chmod $PERM $CHGALL # Removes empty backups. find $STORAGE -size 45c -type f -exec rm {} \; find $STORAGE -size 0c -type f -exec rm {} \; fi # END