Computer
Back Ups
Page

Revised
March 07, 2015

Weekly / Monthly Incremental
Backup Script

To use this script:

1: Create empty file , such as /usr/local/bin/BU_Weelky.sh /opt/local/bin/BU_Weekly.sh or to place the script into.

2: Set permissions.   Make sure that it is executable.   Mine is set to 770 / rwxrwx---

3: Open the empty file in text editor.   Copy script text below, then paste into file.

4: Configure script under the "CONFIGURE SECTION".

5: Create the directory that stores the backup, such as /mnt/backups/Incremental.

6: Run the script in a terminal to check for errors.

    # cd /usr/local/bin

    # BU_Weekly.sh

7: Set CRON to run script as needed.


#! /bin/bash
# See http://www.jperkins.us/computer/home_network/
# Author: Jerry Perkins, Nashville, Tennessee
# Last revision September 23, 2006
#
# Purpose: To make a weekly or monthly incremental
# backup using a Linux / UNIX machine.
#
# --------- USER NOTES ----------
#
# Examples:
# /usr/local/bin/BU_Weekly.sh, Run every Thursday at 12:20 AM
# /opt/local/bin/BU_Month.sh, Run first day of month at 2:05 AM
#
#
# --------- CONFIGURE SECTION ----------
#
# Set path to where to backups will be stored.
# Example: STORAGE="/mnt/backups/Incremental"
STORAGE="/mnt/backups/Incremental"
#
# List the directories that are to be backed up.
# Example: PATHLIST="/boot /etc /home /opt /root /srv /usr/local /var"
# 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*"
# PATHLIST="/boot /etc /home /opt /root /srv /usr/local /var"
PATHLIST="/boot /etc /home /opt /root /srv /usr/local /var"
#
# Set the period of days between backups, plus one day.
# The one day covers the few minutes after midnight that the
# script runs.
# Example: PERIOD="-8" (for weekly)
# Example: PERIOD="-32" (for monthly)
PERIOD="-8"
#
# Set User Name. This changes the backup files Owner.
# Example: FILEOWNER="joew"
FILEOWNER="joew"
#
# Set Group Name. This changes the backup files Group.
# Example: FILEGROUP="wilson"
FILEGROUP="wilson"
#
# Set permissions. Suggest either 400 for owner read, or
# 440 for owner and group read.
# Example: PERM="400"
PERM="440"
#
# Give the file name a prefix.
# Example: FILEGROUP="Weekly_"
# Example: FILEGROUP="Monthly-Joes_"
FILEPRE="Weekly-on-My_Box_"
#
# --------- NO EDITING BELOW THIS LINE ----------
DAYNAME=`date +%Y-%m-%d`
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=$FILEPRE$DIRNAME$DASH$DAYNAME$FILEPOST
     if [ -e $LIST ]; then
        find $LIST -mtime $PERIOD -type f | tar zcfP $FILENAME -T-
     fi
  done
  CHGALL="*"$DAYNAME$FILEPOST
  chown $FILEOWNER $CHGALL
  chgrp $FILEGROUP $CHGALL
  chmod $PERM $CHGALL
fi
# END


If you have any comments, problems, questions or suggestions, please send me an e-mail at

Updated;   This page was last updated on Mar 07 , 2015 .

Any Browser        Gates Free        Valid XHTML 1.0! Valid CSS!

Linux Logo