Added support for incremental backups
This commit is contained in:
parent
3d38d0ccc6
commit
6cd97c474f
41
autotape.sh
41
autotape.sh
@ -1,16 +1,19 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
### Config options ###
|
### Config options ###
|
||||||
|
INCREMENTAL="yes" # yes/no (yes for incremental backup, no for full backup)
|
||||||
BACKUP_DIRS="/mnt/raid1/backups/weekly"
|
BACKUP_DIRS="/mnt/raid1/backups/weekly"
|
||||||
DRIVE="/dev/st0"
|
DRIVE="/dev/st0"
|
||||||
|
SNAPSHOT="/mnt/raid1/backups/weekly.snar" # If using incremental backups
|
||||||
RECHECK_WAIT=1200
|
RECHECK_WAIT=1200
|
||||||
MT="/bin/mt"
|
MT="/bin/mt"
|
||||||
TAR="/bin/tar"
|
TAR="/bin/tar"
|
||||||
|
CP="/bin/cp"
|
||||||
|
|
||||||
|
|
||||||
### Functions ###
|
### Functions ###
|
||||||
|
|
||||||
Do_backup()
|
Do_full_backup()
|
||||||
{
|
{
|
||||||
sleep 15 # Wait for the tape to get ready...
|
sleep 15 # Wait for the tape to get ready...
|
||||||
echo "Doing backup..."
|
echo "Doing backup..."
|
||||||
@ -21,6 +24,18 @@ Do_backup()
|
|||||||
exit 0
|
exit 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Do_inc_backup()
|
||||||
|
{
|
||||||
|
${CP} ${SNAPSHOT} ${SNAPSHOT}\-1
|
||||||
|
sleep 15 # Wait for the tape to get ready...
|
||||||
|
echo "Doing backup..."
|
||||||
|
${TAR} -cf ${DRIVE} -g ${SNAPSHOT}\-1 ${BACKUP_DIRS}
|
||||||
|
echo "Backup done!"
|
||||||
|
sleep 120 #Just in case wait for the tape drive
|
||||||
|
${MT} -f ${DRIVE} offline
|
||||||
|
exit 0
|
||||||
|
}
|
||||||
|
|
||||||
Check_drive()
|
Check_drive()
|
||||||
{
|
{
|
||||||
if [ ! -e ${DRIVE} ]; then
|
if [ ! -e ${DRIVE} ]; then
|
||||||
@ -73,6 +88,14 @@ for dirtest in ${BACKUP_DIRS}; do
|
|||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Check_snapshot()
|
||||||
|
{
|
||||||
|
if [ ! -e ${SNAPSHOT} ]; then
|
||||||
|
echo "${SNAPSHOT} does not exist" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
### Main routine ###
|
### Main routine ###
|
||||||
|
|
||||||
@ -82,6 +105,11 @@ Check_utils
|
|||||||
# Check if the dirs we want to backup exists
|
# Check if the dirs we want to backup exists
|
||||||
Check_backupdir
|
Check_backupdir
|
||||||
|
|
||||||
|
# Check if the snapshot file exist (if running incremental backup)
|
||||||
|
if [ ${INCREMENTAL} == "yes" ]; then
|
||||||
|
Check_snapshot
|
||||||
|
fi
|
||||||
|
|
||||||
# Check and repeat until the tape drive is on/connected
|
# Check and repeat until the tape drive is on/connected
|
||||||
EXIT_STATE=3
|
EXIT_STATE=3
|
||||||
while [ ${EXIT_STATE} != 0 ]; do
|
while [ ${EXIT_STATE} != 0 ]; do
|
||||||
@ -101,5 +129,14 @@ while [ ${EXIT_STATE} != 0 ]; do
|
|||||||
done
|
done
|
||||||
|
|
||||||
# Finally, begin with the backup!
|
# Finally, begin with the backup!
|
||||||
Do_backup
|
if [ ${INCREMENTAL} == "yes" ]; then
|
||||||
|
Do_inc_backup
|
||||||
|
|
||||||
|
elif [ ${INCREMENTAL} == "no" ]; then
|
||||||
|
Do_full_backup
|
||||||
|
|
||||||
|
else
|
||||||
|
echo "I don't know what to do, enter yes or no in $INCREMENTAL" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user