Title: Automatic model of full and differential backup. Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.
The following provides a simple script file as an automated model for both full and differential backup. Before using this script, check the environment variables defined in the script header to meet your needs.
#! /Bin/sh
#
#######################################
#
# TAR backup script to cover daily and weekly backups on one tape.
# Generic UNIX version-edit variables as required
#
# For this to work, it MUST be started on a Monday!
#
# Copyright (c) 1999, Tim Jones
# Permission granted for use/modification
#
# Tim Jones/Linux Magazine provide this shell script with no warranty
# (Implied or otherwise)
#
########################################
DOW = 'date + % W'
DATE = 'date + % d'
DAY = 'date + %'
DEVICE = "my rewind tape" # Rewinding tape drive
NDEVICE = "MY NO_REWIND TAPE" # non-rewinding tape drive
REWIND = "mt-f $ DEVICE rewind"
EOD = "mt-f $ NDEVICE eod"
FSF = "mt-f $ NDEVICE fsf"
MAILLIST = "root" # list of users to receive backup notice
If [$ DOW = "6"]
Then
# This is Saturday, so append and write the whole system!
$ EOD
Echo $ DATE>/tmp/. LASTFULL
Tar-cvvf $ NDEVICE/>/tmp/backup.txt
$ REWIND
$ FSF 5
Tar-dvf $ NDEVICE>/tmp/backup.txt
$ REWIND
Cp/tmp/. LASTFULL/etc/. LASTFULL
Else
# This is not Saturday
Case $ DOW in
0)
# It's Sunday-nothing to do
Exit 0
;;
1)
# Monday, Let the tape rewind for the difference verification
Echo $ DATE>/tmp/. LASTINC
Tar-cvvf $ DEVICE -- newer 'cat/etc/. lastfull'/>/tmp/backup.txt
Cp/tmp/. LASTINC/etc/. LASTINC
;;
*)
# Other Days, must rewind manually and Inspect,-I
$ EOD
Echo $ DATE>/tmp/. LASTINC
Tar-cvvf $ NDEVICE -- newer 'cat/etc/. lastinc'/>/tmp/backup
$ REWIND
$ FSF 'expr $ DOW-1'
Echo "************* Verifying $ {DAY}'s backup">/tmp/backup.txt
Tar -- dvf $ NDEVICE>/tmp/backup.txt
Cp/tmp/. LASTINC/etc/. LASTINC
$ REWIND
Esac
Fi
Mail $ MAILLIST </tmp/backup.txt
Rm-f/tmp/backup.txt
# END OF SCRIPT