![](/@@/translation-newline)
#!/bin/bash
![](/@@/translation-newline)
####################################
![](/@@/translation-newline)
#
![](/@@/translation-newline)
# Backup to NFS mount script with
![](/@@/translation-newline)
# grandfather-father-son rotation.
![](/@@/translation-newline)
#
![](/@@/translation-newline)
####################################
![](/@@/translation-newline)
# What to backup.
![](/@@/translation-newline)
backup_files="/home /var/spool/mail /etc /root /boot /opt"
![](/@@/translation-newline)
# Where to backup to.
![](/@@/translation-newline)
dest="/mnt/backup"
![](/@@/translation-newline)
# Setup variables for the archive filename.
![](/@@/translation-newline)
day=$(date +%A)
![](/@@/translation-newline)
hostname=$(hostname -s)
![](/@@/translation-newline)
# Find which week of the month 1-4 it is.
![](/@@/translation-newline)
day_num=$(date +%d)
![](/@@/translation-newline)
if (( $day_num <= 7 )); then
week_file="$hostname-week1.tgz"
![](/@@/translation-newline)
elif (( $day_num > 7 && $day_num <= 14 )); then
week_file="$hostname-week2.tgz"
![](/@@/translation-newline)
elif (( $day_num > 14 && $day_num <= 21 )); then
week_file="$hostname-week3.tgz"
![](/@@/translation-newline)
elif (( $day_num > 21 && $day_num < 32 )); then
week_file="$hostname-week4.tgz"
![](/@@/translation-newline)
fi
![](/@@/translation-newline)
# Find if the Month is odd or even.
![](/@@/translation-newline)
month_num=$(date +%m)
![](/@@/translation-newline)
month=$(expr $month_num % 2)
![](/@@/translation-newline)
if [ $month -eq 0 ]; then
month_file="$hostname-month2.tgz"
![](/@@/translation-newline)
else
month_file="$hostname-month1.tgz"
![](/@@/translation-newline)
fi
![](/@@/translation-newline)
# Create archive filename.
![](/@@/translation-newline)
if [ $day_num == 1 ]; then
[tab]
archive_file=$month_file
![](/@@/translation-newline)
elif [ $day != "Saturday" ]; then
archive_file="$hostname-$day.tgz"
![](/@@/translation-newline)
else
[tab]
archive_file=$week_file
![](/@@/translation-newline)
fi
![](/@@/translation-newline)
# Print start status message.
![](/@@/translation-newline)
echo "Backing up $backup_files to $dest/$archive_file"
![](/@@/translation-newline)
date
![](/@@/translation-newline)
echo
![](/@@/translation-newline)
# Backup the files using tar.
![](/@@/translation-newline)
tar czf $dest/$archive_file $backup_files
![](/@@/translation-newline)
# Print end status message.
![](/@@/translation-newline)
echo
![](/@@/translation-newline)
echo "Backup finished"
![](/@@/translation-newline)
date
![](/@@/translation-newline)
# Long listing of files in $dest to check file sizes.
![](/@@/translation-newline)
ls -lh $dest/