(My) automatic, remote,
backup solution


Who should use this backup solution

What we need from this backup solution

  1. We need backup to be REGULARY.
  2. We need backup first to be full, then only changed files.
  3. We need solution to put files to other phisical system (UNIX, but why not Win 95 / 98 / NT)
  4. Solution must be automatic.
  5. The system must notify us, when backup is done.

What we DO NOT need from this backup solution

  1. We need it to be abstract, we do not need to care about backup storage (HDD, CD_Rom, ZIP or Tape)
  2. We do not need to have NFS to backup storage.

What additional hardware/software we need

We need have a trusted system with a FTP account:

OS: -some-
FTP: Yes, with one account, that can have rights to upload BIG FILES
Disk space: Enought for backups
External storage: ZIP, Tape, CDROM etc... (it can be on different system, that can have network access to same system, Ms Windows network or NFS for example)

All backups will be stored into our FTP account home directory ('/var/backup' for example), and when we deside we can put it on CD Rom or tape (every few mounths, or every week...:)

The backuped system

Ok this is the main topic.

We must deside following things:

  1. Who will make backups? This can be 'root' user, but this can be some another user. If you deside that it will be no root, be sure this user have rights to READ ALL directoryes and files that you want to backup.
  2. What phogram you will use for backing up. There are standard on UNIX systems, so this will be TAR (Tape_ARchive).
  3. TAR do not use compression. It will be great to make compression too. There are two good programs to do this. GZIP and BZIP. Second compress better, but GZIP is faster and most often used. The script will use GZIP.
  4. How files will be sended to another system? e_mail or FTP? My first version uses e_mail, but there are a problems, when you try to mail file biggest than 5 MB :)))). FTP is better...
  5. How FTP will be logged in on remote system? The best way is to setup a ".netrc" file in your home directory. (man ftp:)))
  6. How often you will backing up your data? Setup it into crontab:
...
# at 3:00am on every 1st day of week (possibly monday:))
0 3 * * 1 /root/cron/full_backup
...

Where /root/cron/full_bckup is file like this:

#!/bin/sh

tape /www www
tape /var/named named
tape /etc etc
tape /usr/local/apache/conf httpd

#DONT THINK THAT THIS IS MY (YOURS) REAL DIRECTORIES :))))
#REPLACE THEM :))))

And in the end the BIG tape script. It must be in path.

#!/bin/sh
########################################
#                                      #
#             THE TAPE 1.0             #
#                                      #
# Copyleft Sep.1999, Nikolay Mijaylov  #
#                                      #
# nmmm@nmmm.nu http://www.nmmm.nu/     #
#                                      #
# You can redistribute this script     #
# under terms of GPL.                  #
#                                      #
# Please, if you have some another     #
# ideas about great modifications      #
# in this script, I WANT TO KNOW :)    #
#                                      #
########################################







#===================================
#MAIN
#===================================

#Directory for back up
DIR=$1/

#Global name to backing up
NAME=$2

#Backup system dir, where date files will be stored
BACKUP_SYS_DIR=/root/cron/

#File name with date
DATE_FILE=$BACKUP_SYS_DIR/.backup_date.$NAME

#Directory where backup will be stored locally
BACKUP_DIR=/var/backup/local/

#FTP Host where files should be uploaded
FTP_HOST=trusted.foo.org

#Mail of master
MAIL_RCPT=nmmm@nmmm.nu



#==================================
#DATES
#==================================

#Date when time begins :)))
DATE_BEGIN="1 jan 1980"

#Today()
DATE_TODAY=`date --utc`

read_date(){
        # Get the date
        DATE=`cat "$DATE_FILE" 2> /dev/null`

        # Check it
        if [ "$DATE" = "" ] ; then
                DATE="blah_blah"
        fi

        if ( date --date "$DATE" 1> /dev/null 2> /dev/null ) ; then
                # Fixing format, noo data change...
                DATE=`date --date "$DATE" --utc` ;
        else
                # Fixing date, reset to 01.01.1980
                DATE=`date --date "$DATE_BEGIN" --utc`
        fi

        #tar --after-date $DATE -c * > hell.tar
        echo $DATE
}



#==============================================================
#TAPE / GZIP
#==============================================================

#Date format
DATE_FORMAT="%Y-%m-%d"

#The date of last backup
DATE=`read_date`

#Backup file name (today).(last).(name)
#
FILE=`date +"$DATE_FORMAT"`.`date +"$DATE_FORMAT" --date "$DATE"`.$NAME

cd $BACKUP_DIR

# Tape it
tar --after-date "$DATE" -c "$DIR" > "$FILE.tar"

# Compress it
rm -f "$FILE.tar.gz"
gzip "$FILE.tar"





#================================================================
# Set new backup date (today)
#================================================================
echo "$DATE_TODAY" > "$DATE_FILE"






#================================================================
# FTP it
#================================================================
ftp $FTP_HOST << [DONE]

put $FILE.tar.gz
quit
[DONE]




#================================================================
#Mail it
#================================================================
mail "$MAIL_RCPT" -s "backup ok, name=$NAME" << [DONE1]
Hello Master,
Backup was successfully maded.

DATE LAST BACKUP: $DATE
DATE THIS BACKUP: $DATE_TODAY
NAME OF BACKUP  : $NAME
[DONE1]




#================================================================
#Clean up
#================================================================
#rm $FILE.tar.gz

Description:

How to implement:

  1. Copy it
  2. Review it (for security holes)
  3. Make/change directoryes
  4. Edit MAIN section in "TAPE"
  5. Edit crontab
  6. Thats all :)))

Congratelations, you have backup solution! Have fun...
Copyleft 2.Sep.1999,
Nikolay Mijaylov
nmmm@nmmm.nu
http://www.nmmm.nu/